[英]The argument type 'Widget Function(BuildContext, T, Widget)' can't be assigned to the parameter type 'Widget Function(BuildContext, T, Widget?)
I have a base widget class which no longer works since I upgraded the provider version to 5.0.0.我有一个基本小部件 class,自从我将提供程序版本升级到 5.0.0 后它就不再工作了。
At builder: widget.builder
I am getting this error:在
builder: widget.builder
我收到这个错误:
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?)”
How can I fix this?我怎样才能解决这个问题?
Here is my code这是我的代码
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class BaseWidget<T extends ChangeNotifier> extends StatefulWidget {
final Widget Function(BuildContext context, T model, Widget child) builder;
final T model;
final Widget child;
final Function(T) onModelReady;
BaseWidget({
Key? key,
required this.builder,
required this.model,
required this.child,
required this.onModelReady,
}) : super(key: key);
_BaseWidgetState<T> createState() => _BaseWidgetState<T>();
}
class _BaseWidgetState<T extends ChangeNotifier> extends State<BaseWidget<T>> {
late T model;
@override
void initState() {
model = widget.model;
widget.onModelReady(model);
super.initState();
}
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<T>(
create: (context) => model,
child: Consumer<T>(
builder: widget.builder,
child: widget.child,
),
);
}
}
I pasted the code into Android studio and it looks like to need to change the following:我将代码粘贴到 Android studio 中,看起来需要更改以下内容:
From从
final Widget Function(BuildContext context, T model, Widget child) builder;
To到
final Widget Function(BuildContext context, T model, Widget? child) builder;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.