我想将文档和 user 对象传递到一个对话框,该对话框在单独的文档中编码,可以对该用户的文档执行操作。 / p>
传递信息的代码是:
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。”
如果有人能提供我的见解,我将不胜感激!
答案 0 :(得分:1)
更改此:
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),