CAB
CAB

Reputation: 39

Flutter - Error BlocProvider void' doesn't conform to the bound

 return Scaffold(
  backgroundColor: Colors.white,
  body: Center(
    child: BlocProvider(
      // create: (context) => BlocProvider.of<LoginBloc>(context)..add(LoginSubmit(_usernameController.text, _passwordController.text)),
      create: (context) => LoginBloc(BlocProvider.of<AuthBloc>(context)).add(LoginSubmit(_usernameController.text, _passwordController.text)),
      // BlocProvider.of<LoginBloc>(_)..add(LoginSubmit(_usernameController.text, _passwordController.text)),

      child: BlocConsumer<LoginBloc, LoginState>(listener: (context, state) async {
        if (state is LoginFailed) {
          CustomeAlertDialog.show(context, "", state.error, key: null);
        }

please help me, i got error flutter : Error: Inferred type argument 'void' doesn't conform to the bound 'Cubit' of the type variable 'T' on 'BlocProvider'. lib/login_page.dart:106

Upvotes: 1

Views: 932

Answers (1)

chuanpham
chuanpham

Reputation: 469

BlocConsumer is a mix between “BlocListener” and “BlocBuilder”. This is used when we want to draw something based on the current state and execute some actions depending on the new arriving states.

I think you should use BlocConsumer like below:

BlocConsumer<BlocA, BlocAState>(
  listener: (context, state) {
    // do stuff here based on BlocA's state
  },
  builder: (context, state) {
    // return widget here based on BlocA's state
  }
)

Upvotes: 0

Related Questions