gpt4 book ai didi

flutter - Flutter:通过Navigator.Push传递多个数据,然后将数据弹出

转载 作者:行者123 更新时间:2023-12-03 04:10:18 25 4
gpt4 key购买 nike

如何将多个变量传递到新屏幕,然后将该数据传递回?
我可以成功地将用户名传递回去,但是现在我至少需要6个变量。

到目前为止,这就是我想出的。我似乎无法弄清楚。

 Future<void> createUserInFirestore(FirebaseUser currentUser) async {
// 1) check if user exists in user collection in database (according to ID)
DocumentSnapshot doc = await usersRef.document(currentUser.uid).get();
if (!doc.exists) {
// 2) if user does not exist, take them to user create account.
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => new CreateAccount(username: username),
),
);
// 3) get username from create account, use it to make new user documents in users collection.
usersRef.document(currentUser.uid).setData({
"uid": currentUser.uid,
"username": username,
"user_profile_photo": currentUser.photoUrl == null? {} : currentUser.photoUrl,
"email": currentUser.email,
"account_created": timestamp,
});

}

这是我的Submit方法的回调;
 _submit() {
final form = _formKey.currentState;
if (form.validate()) {
form.save();
SnackBar snackbar = SnackBar(
content: Text("Welcome $widget.username!"),
);
_scaffoldKey.currentState.showSnackBar(snackbar);
Timer(Duration(seconds: 2), () {
Navigator.pop(context, username);
});
}

我已经被困了4天了,试图解决这个问题。

最佳答案

编辑:好,您说我对一个变量做了,并要求至少6个变量。

Map<String, dynamic> yourMap = {
"uid": currentUser.uid,
"username": username,
"user_profile_photo": currentUser.photoUrl == null? {} : currentUser.photoUrl,
"email": currentUser.email,
"account_created": timestamp,
};

1-这样更新 Navigator.pop Navigator.pop(context, yourMap}
2-这样更新 Navigator.push Navigator.push(context, MaterialPageRoute(builder: (_) => WhichPageYouWantPage(yourMap)));
您的 CreateAccount代码很好,只需像这样更新 Navigator.push(U可以带回所有内容) String username = await Navigator.push(...);

关于flutter - Flutter:通过Navigator.Push传递多个数据,然后将数据弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58270875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com