@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: AppPages.allBlocProviders(context) ,
child: ScreenUtilInit(
builder: (context, child) =\> MaterialApp(
debugShowCheckedModeBanner: false,
home: const Welcome(),
theme: ThemeData(
appBarTheme: const AppBarTheme(
iconTheme: IconThemeData(
color: AppColors.primaryText
),
elevation: 0,
backgroundColor: Colors.white
)
),
onGenerateRoute: AppPages.GenerateRouteSettings,
),
)
);
}
字符串
这是主要的dart文件导致的错误
class PageEntity{
String route;
Widget page;
dynamic bloc;
PageEntity({required this.route, required this.page, this.bloc});
}
型
这是一个实体类,它帮助通过提供程序进行验证。
class AppPages{
static List<PageEntity> routes (){
return [
PageEntity(
route: AppRoutes.INITIAL,
page: const Welcome(),
bloc: BlocProvider(create: (_)=>WelcomeBloc(),)
),
PageEntity(
route: AppRoutes.SING_IN,
page: const SignInPage(),
bloc: BlocProvider(create: (_)=>SignInBlocs(),)
),
PageEntity(
route: AppRoutes.REGISTER,
page: const Register(),
bloc: BlocProvider(create: (_)=>RegisterBlocs(),)
),
PageEntity(
route: AppRoutes.APPLICATION,
page: const Welcome(),
),
];
}
// return all the bloc providers
static List<dynamic> allBlocProviders(BuildContext context){
List<dynamic> blocProviders = <dynamic>[];
for(var bloc in routes()){
blocProviders.add(bloc.bloc);
}
return blocProviders;
}class AppPages{
static List<PageEntity> routes (){
return [
PageEntity(
route: AppRoutes.INITIAL,
page: const Welcome(),
bloc: BlocProvider(create: (_)=>WelcomeBloc(),)
),
PageEntity(
route: AppRoutes.SING_IN,
page: const SignInPage(),
bloc: BlocProvider(create: (_)=>SignInBlocs(),)
),
PageEntity(
route: AppRoutes.REGISTER,
page: const Register(),
bloc: BlocProvider(create: (_)=>RegisterBlocs(),)
),
PageEntity(
route: AppRoutes.APPLICATION,
page: const Welcome(),
),
];
}
// return all the bloc providers
static List<dynamic> allBlocProviders(BuildContext context){
List<dynamic> blocProviders = <dynamic>[];
for(var bloc in routes()){
blocProviders.add(bloc.bloc);
}
return blocProviders;
}
}
型
这是所有供应商所在的地方
我尝试的是:
我尝试将返回类型dynamic更改为BlocProvider
。
我将providers属性更改为
AppPages.allBlocProviders(context) to [...AppPages.allBlocProviders(context)].
型
1条答案
按热度按时间km0tfn4u1#
你不应该在
allBlocProviders
函数中使用dynamic
,所以你写的三个地方都应该写dynamic
,你应该写BlocProvider
,并检查块是否为null,比如字符串
以及
PageEntity
的变化型
到
型