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

Viewed 268
 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

  • 'Cubit' is from 'package:bloc/src/cubit.dart' ('/D:/Master/flutter/.pub-cache/hosted/pub.flutter-io.cn/bloc-6.1.3/lib/src/cubit.dart'). package:bloc/src/cubit.dart:1
  • 'Object' is from 'dart:core'. Try specifying type arguments explicitly so that they conform to the bounds. child: BlocProvider(
1 Answers

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
  }
)
Related