felangel / bloc

A predictable state management library that helps implement the BLoC design pattern

Home Page:https://bloclibrary.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fix: Error: A value of type 'ABloc' can't be returned from a function with return type 'Never'

jonathanMNg opened this issue · comments

Description
When I create an array of BlocProvider, I'm seeing this error:

final _navScreens = [ BlocProvider( create: (context) => ABloc(), child: const AScreen(), ), BlocProvider( create: (context) => BBloc(), child: const BScreen(), ) ];

`lib/screens/home/home_screen.dart:125:26: Error: A value of type 'ABloc' can't be returned from a function with return type 'Never'.

  • 'ABloc' is from 'a.dart' ('lib/bloc/a/a_bloc.dart').
    create: (context) => ABloc(),
    ^
    lib/screens/home/home_screen.dart:129:26: Error: A value of type 'BBloc' can't be returned from a function with return type 'Never'.
  • 'BBloc' is from 'b.dart' ('lib/bloc/b/b_bloc.dart').
    create: (context) => BBloc(),
    ^
    `
    But when I do this, the error go away (add a non BlocProvider to the array)

final _navScreens = [ BlocProvider( create: (context) => ABloc(), child: const AScreen(), ), BlocProvider( create: (context) => BBloc(), child: const BScreen(), ), const SizedBox.shrink(), ];
Steps To Reproduce
Add this code
final _navScreens = [ BlocProvider( create: (context) => ABloc(), child: const AScreen(), ), BlocProvider( create: (context) => BBloc(), child: const BScreen(), ) ];
Expected Behavior
Should execute without issue

Hi @jonathanMNg 👋
Thanks for opening an issue!

Are you able to share a link to a minimal reproduction sample either on GitHub or DartPad? Thanks!

Hi,
Thanks for the response and this great package.
Here is my DartPad that demonstrate the error:
https://dartpad.dev/?id=f0183714be9e851ed80930cfae689765

@jonathanMNg thanks for sharing! I'm not sure what you're trying to achieve. That error can be resolved by specifying a type on _navScreens like:

final _navScreens = <Widget>[
  BlocProvider(
    create: (context) => ABloc(),
    child: const AScreen(),
  ),
  BlocProvider(
    create: (context) => BBloc(),
    child: const BScreen(),
  ),
];

Hope that helps!

Closing for now but if you still have questions lmk and I'm happy to continue the conversation 👍