我试图解决这两个问题,但却找不到解决办法:
之前移动所有位置参数
Padding(
padding: const EdgeInsets.only(top: 15.0, bottom: 15.0),
child: TextField(
controller: phoneController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: 'Phone Number',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)
)
),
onChanged: (value){
},
)
),
Padding(
padding: const EdgeInsets.only(top:15.0, bottom: 15.0),
child: Row(
children: <Widget>[
Expanded(
child: RaisedButton(
color:Theme.of(context).primaryColorDark,
textColor: Theme.of(context).primaryColorLight,
child: const Text(
'Save',
textScaleFactor: 1.5,
),
onPressed: (){
if(contact == null){
// add data
contact = Contact(nameController.text,phoneController.text);
}else{
//edit data
contact.name = nameController.text;
contact.phone = phoneController.text;
}
Navigator.pop(context, contact);
},
),
),
Container(width: 5.0),
Expanded(
child: RaisedButton(
color: Theme.of(context).primaryColorDark,
textColor: Theme.of(context).primaryColorLight,
child: const Text(
'Cancel',
textScaleFactor: 1.5,
),
onLongPress: (){
Navigator.pop(context);
}, onPressed: () { },
),
),
],
)
)
发布于 2022-01-25 14:06:13
您的错误消息已经为您提供了如何解决该问题的提示:
"Positional arguments must occur before named arguments & Too many positional arguments"
第一部分:位置参数必须发生在命名参数之前
// Where you defined your method
myMethod(positionalParameter1, positionalParameter2, name: namedParameter1) {}
// Where you use it (where the error occurs)
onPressed: myMethod(name: namedParameter1, positionalParameter1, positionalParameter2)
// Solution, assign them in the correct order :)
onPressed: myMethod(positionalParameter1, positionalParameter2, name: namedParameter1)
第二部分:太多的位置参数
// Where you defined your method
myMethod(positionalParameter1) {}
// Where you use it (where the error occurs)
onPressed: myMethod(positionalParameter1, positionalParameter2)
// Solution: Don´t assign to many parameters or make sure you defined all of them.
FYI:这也可以应用于类及其构造函数参数/参数!
https://stackoverflow.com/questions/70845660
复制相似问题