gpt4 book ai didi

flutter - flutter -位置参数过多

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

我想将文档用户对象传递到一个对话框,该对话框编码在单独的文档中,该对话框可以对该用户的文档执行操作。

传递信息的代码是:

 Widget _buildFunctionCards(BuildContext context, DocumentSnapshot document, FirebaseUser user) {
return ListTile(
title: GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (_) => FunctionEditOptions(document, user),
);},
child:Container... ()))}

接收单据编码如下:
   class FunctionEditOptions extends StatefulWidget {
FunctionEditOptions({this.db, this.user});
final FirebaseUser user;
final DocumentSnapshot db;
@override
State<StatefulWidget> createState() => FunctionEditOptionsState();
}

class FunctionEditOptionsState extends State<FunctionEditOptions>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation<double> scaleAnimation;

@override

收到的错误消息是:“太多的位置参数:预期0,但找到2。”

如果有人可以提供见解,我将不胜感激!

最佳答案

更改此:

builder: (_) => FunctionEditOptions(document, user),

对此
builder: (_) => FunctionEditOptions(db: document, user: user), // or:
builder: (_) => FunctionEditOptions(user: user, db: document), // both ways are correct

在括号内指定参数时,它们将变为可选参数,并且可能会出现乱序。因此,在传递参数时必须命名参数。

另一种方法是从括号中取出参数,并确保参数正确无误。
FunctionEditOptions(this.db, this.user);

并这样称呼:
builder: (_) => FunctionEditOptions(document, user),

可以混合使用
FunctionEditOptions(this.db, {this.user});

并这样称呼:
builder: (_) => FunctionEditOptions(document, user: user),

关于flutter - flutter -位置参数过多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61447494/

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