Skip to content

Are nested BlocProviders normal? #6

@aytunch

Description

@aytunch

In main.dart there are 2 BlocProviders. I am not an expert on bloc however I thought we should have the BlocProvider on top level and when we want to use it we use "context.of." to access it inside ContainerPage. Sorry if this is the normal usage

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: BlocProvider(
          builder: (BuildContext context) => FragmentBloc(),
          child: ContainerPage()),
    ),
  ));
}

class ContainerPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    FragmentManager().setRoutes(<String, Widget>{
      FRAGMENT_1: Fragment1(),
      FRAGMENT_2: Fragment2(),
      FRAGMENT_3: Fragment3(),
      FRAGMENT_4: Fragment4(),
    });

    return BlocProvider<FragmentBloc>(
      builder: (BuildContext context) => FragmentBloc(),
      child:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions