使用提供程序 class,此错误不断返回:尝试调用 Provider.of<dynamic>
This error keeps returning, using the Provider class: Tried to call Provider.of<dynamic>
Error: Tried to call Provider.of<dynamic>.
This is likely a mistake and is therefore
unsupported.
If you want to expose a variable that can be anything, consider changing
`dynamic` to `Object` instead.
'package:provider/src/provider.dart':
Failed assertion: line 307 pos 7: 'T != dynamic'
将它从动态转换为对象是什么意思?
代码:
body: SingleChildScrollView(
child: Container(
width: MediaQuery.of(context).size.width,
child: Column(
children: <Widget>[
FutureBuilder(
future: Provider.of(context).auth.getCurrentUser(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return displayUserInformation(context, snapshot);
} else {
return CircularProgressIndicator();
}
您需要指定 return 静态方法的类型 Provider.of<T>(context)
。
此处不能选择动态 ;-)
Flutter 文档中给出的示例不言自明
ChangeNotifierProvider(
create: (context) => CartModel(),
child: MyApp(),
),
....
Provider.of<CartModel>(context, listen: false).removeAll();
Error: Tried to call Provider.of<dynamic>.
This is likely a mistake and is therefore
unsupported.
If you want to expose a variable that can be anything, consider changing
`dynamic` to `Object` instead.
'package:provider/src/provider.dart':
Failed assertion: line 307 pos 7: 'T != dynamic'
将它从动态转换为对象是什么意思?
代码:
body: SingleChildScrollView(
child: Container(
width: MediaQuery.of(context).size.width,
child: Column(
children: <Widget>[
FutureBuilder(
future: Provider.of(context).auth.getCurrentUser(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return displayUserInformation(context, snapshot);
} else {
return CircularProgressIndicator();
}
您需要指定 return 静态方法的类型 Provider.of<T>(context)
。
此处不能选择动态 ;-)
Flutter 文档中给出的示例不言自明
ChangeNotifierProvider(
create: (context) => CartModel(),
child: MyApp(),
),
....
Provider.of<CartModel>(context, listen: false).removeAll();