简体   繁体   English

type '(BuildContext, Widget) => ChangeNotifierProvider<>' 不是类型转换中类型 '(BuildContext, Widget?) => Widget' 的子类型

[英]type '(BuildContext, Widget) => ChangeNotifierProvider<>' is not a subtype of type '(BuildContext, Widget?) => Widget' in type cast

type '(BuildContext, Widget) => ChangeNotifierProvider' is not a subtype of type '(BuildContext, Widget?) => Widget' in type cast type '(BuildContext, Widget) => ChangeNotifierProvider' 不是类型转换中类型 '(BuildContext, Widget?) => Widget' 的子类型

Hi, I am facing above error on my old project while I was converting it to Flutter 2.5, can anyone help me to figure it out?嗨,我在将旧项目转换为 Flutter 2.5 时遇到了上述错误,谁能帮我弄清楚?

abstract class Role {
  Widget homeBuilder(BuildContext context);
   Map<String, WidgetBuilder>? routes;

  /// The navigatorBuilder allows you to insert widgets between MaterialApp and its Navigator.
  /// This is useful for providing the logged in Talent or Recruiter
   TransitionBuilder? navigatorBuilder;
}




@override
  TransitionBuilder navigatorBuilder =
      (BuildContext context, Widget navigator) {
    String token = Provider.of<AuthBloc>(context).token;
    MyNotifications.setUpFirebaseMessaging(context);
    return ChangeNotifierProvider<Talent>(
      create: (ctx) =>
      (Provider.of<AuthBloc>(context).role as TalentRole).talent
        ..setAuthToken(token),
      child: navigator,
    );
  };

TransitionBuilder:过渡生成器:

typedef TransitionBuilder = Widget Function(BuildContext context, Widget? child);

expects a context and a child.期待一个上下文和一个孩子。 The child is of type Widget?孩子是Widget?类型Widget? , note the question mark. ,注意问号。 This shows you the widget can be null.这表明小部件可以为空。

If you define a TransitionBuilder you need to show that too, so you need to change如果你定义了一个 TransitionBuilder 你也需要展示它,所以你需要改变

@override
  TransitionBuilder navigatorBuilder =
      (BuildContext context, Widget navigator) {

to

@override
  TransitionBuilder navigatorBuilder =
      (BuildContext context, Widget? navigator) { //add the question mark

More info on null safety: https://dart.dev/null-safety/understanding-null-safety有关空安全的更多信息: https : //dart.dev/null-safety/understanding-null-safety

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通用飞镖:类型 &#39;(BuildContext, String) =&gt; Padding&#39; 不是类型 &#39;(BuildContext, dynamic) =&gt; Widget&#39; 的子类型 - Generic dart: type '(BuildContext, String) => Padding' is not a subtype of type '(BuildContext, dynamic) => Widget' &#39;列表<dynamic> &#39; 不是类型 &#39;(BuildContext, int) =&gt; Widget&#39; 的子类型 - 'List<dynamic>' is not a subtype of type '(BuildContext, int) => Widget' flutter 引发了另一个异常:类型&#39;(BuildContext,int)=&gt;动态&#39;不是类型&#39;(BuildContext,int)=&gt; Widget&#39;的子类型 - Another exception was thrown: type '(BuildContext, int) => dynamic' is not a subtype of type '(BuildContext, int) => Widget' 返回类型 'Widget Function(BuildContext, Widget)' 不是 'Widget' - The return type 'Widget Function(BuildContext, Widget)' isn't a 'Widget' 无法将参数类型“Widget Function(BuildContext)”分配给参数类型“Widget Function(BuildContext, Widget)”? - The argument type 'Widget Function(BuildContext)' can't be assigned to the parameter type 'Widget Function(BuildContext, Widget)'? Flutter 中的参数类型“Widget Function(BuildContext)”无法分配给参数类型“Widget Function(BuildContext, Widget)”错误 - The argument type 'Widget Function(BuildContext)' cant be assigned to the parameter type 'Widget Function(BuildContext, Widget)' Error in Flutter 参数类型“Widget Function(BuildContext, Object?)”不能分配给参数类型“Widget Function(BuildContext, dynamic, VxStatus? - The argument type 'Widget Function(BuildContext, Object?)' can't be assigned to the parameter type 'Widget Function(BuildContext, dynamic, VxStatus? 参数类型“Widget Function(BuildContext, T, Widget)”不能分配给参数类型“Widget Function(BuildContext, T, Widget?)” - The argument type 'Widget Function(BuildContext, T, Widget)' can't be assigned to the parameter type 'Widget Function(BuildContext, T, Widget?)' 无法将参数类型“Widget Function(BuildContext, T, Widget)”分配给参数类型“Widget Function(BuildContext, T, Widget?)” - The argument type 'Widget Function(BuildContext, T, Widget)' can't be assigned to the parameter type 'Widget Function(BuildContext, T, Widget?) 参数类型 'Container Function(BuildContext, int)' 不能分配给参数类型 'Widget Function(BuildContext, int, int)' - The argument type 'Container Function(BuildContext, int)' can't be assigned to the parameter type 'Widget Function(BuildContext, int, int)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM