繁体   English   中英

参数类型“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?)'

我一直在按照教程在我们的 flutter web 应用程序中实施 state 管理。 这是教程: https://medium.flutterdevs.com/firebase-authentication-using-provider-in-flutter-522841a2ee4d

现在我正在为我的小部件创建“baseView”model,我有点迷失了,因为我是 flutter 的新手。

class BaseView<T extends BaseModel> extends StatefulWidget {
  final Widget Function(BuildContext context, T model, Widget child) builder;

  const BaseView({
    @required this.builder,
  });

  @override
  _BaseViewState<T> createState() => _BaseViewState<T>();
}

class _BaseViewState<T extends BaseModel> extends State<BaseView<T>> {
  T model = locator<T>();

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<T>.value(
      //builder: (context) => model,
      child: Consumer<T>(builder: widget.builder),
      //notifier: model,
      value: model,
    );
  }
}

首先,我收到“@required this.builder”部分的错误消息: The parameter 'builder' can't have a value of 'null' because of its type, but the implicit default value is 'null'.

对于“Consumer(builder:widget.builder)”部分,我收到此错误:无法The argument type 'Widget Function(BuildContext, T, Widget)' can't be assigned to the parameter type 'Widget Function(BuildContext, T, Widget?)'.

我还有该项目的 Github 存储库的链接,该链接在教程中提供: https://github.com/flutter-devs/flutter_auth_provider

任何帮助将不胜感激!

Widget Function(BuildContext, T, Widget)不能接受Widget Function(BuildContext, T, Widget?)签名所需的null值。

而已。 说得通?

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM