[英]Using Provider in a Stateful Widget
I'm pretty new to Flutter/Firebase and am having an issue with Provider implenetation for a very simple CRUD contacts app.我是 Flutter/Firebase 的新手,并且在一个非常简单的 CRUD 联系人应用程序的 Provider 实现方面遇到了问题。 I'm not sure how to fix this.
我不知道如何解决这个问题。
[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: 'package:provider/src/provider.dart': Failed assertion: line 284 pos 7: 'T != dynamic': Tried to call Provider.of. [VERBOSE-2:ui_dart_state.cc(166)] 未处理的异常:'package:provider/src/provider.dart':断言失败:第 284 行 pos 7:'T != dynamic':试图调用 Provider.of。 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.如果您想公开一个可以是任何变量的变量,请考虑将
dynamic
改为Object
。
Here's the code for the page where the save is done.这是完成保存的页面的代码。
actions: [
IconButton(
icon: Icon(
Icons.done,
color: Colors.white,
),
onPressed: () async {
//save data to firebase
final uid = await Provider.of<dynamic>(context, listen: false)
.auth
.getCurrentUID();
await db
.collection("userData")
.doc(uid)
.collection('contacts')
.add(
{
'Name': widget.contact.name,
'PhoneNumber': widget.contact.phoneNumber,
'Location': widget.contact.location,
'Notes': widget.contact.notes
},
);
Thank you谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.