在我的颤栗应用程序中,有那么多的页面,在大多数页面中,我发送post请求来获取对象列表,为此我必须使用大量的集团和集团提供程序类。是否有任何方法来开发一个通用集团提供程序与通用集团,以便我可以使用它在我的所有网页?
发布于 2019-12-03 08:49:38
您可以直接使用或引用以下两个包的源代码
https://pub.dev/packages/generic_bloc_provider
一个通用的BloC提供商为您的颤振应用程序。代码段
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 --帮助实现BLoC模式的颤振包。
https://stackoverflow.com/questions/59153102
复制相似问题