Reputation: 53
In my flutter application there are so many pages and in most of the pages I send post requests to fetch a list of Objects and I have to use a lot of bloc and bloc provider classes to do so. Is there any way to develop a generic bloc provider with the generic bloc, so that I can use it in all of my pages?
Upvotes: 0
Views: 2354
Reputation: 54417
You can directly use or reference source code of the following two package
https://pub.dev/packages/generic_bloc_provider
A generic BloC Provider for your Flutter apps.
code snippet
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
bloc: AppBloc(),
child: MaterialApp(
title: 'Yo Sleep',
home: MainPage(),
initialRoute: 'main',
routes: {
'main': (context) => MainPage(),
},
),
);
}
}
class MainPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appBloc = BlocProvider.of<AppBloc>(context);
return Scaffold(
body: SafeArea(
child: Column(
children: <Widget>[
Header(),
RecordList(appBloc),
],
),
),
);
}
}
https://pub.dev/packages/flutter_bloc A Flutter package that helps implement the BLoC pattern.
Upvotes: 1