I have made two pages, PersonalPage and InformationPage. I want to transfer some parameters from PersonalPage to InformationPage. Here are my codes. PersonalPage:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Information(phoneNumber: phoneNumber, nickName: nickName, realName: realName, key: key)
),
);
InformationPage:
class Information extends StatelessWidget {
String? phoneNumber;
String? realName;
String? nickName;
Information({required Key key, required this.phoneNumber, required this.realName, required this.nickName})
: super(key: key);
@override
Widget build(BuildContext context) {
// TODO: implement build
//Some codes
}
}
In PersonalPage, there is an error in the line including "builder:":
Undefined name 'key'.
It seems that I need to assign key
. But I don't know what thing I should put to key
. So what should I put to key
? Or can I just take measures to avoid assigning it?
Thanks a lot.
You need to pass Key as the key field is set required.
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Information(key: Key('keyName'), phoneNumber: phoneNumber, nickName: nickName, realName: realName, key: key)
),
);