Flutter parameters transfering across pages: What about the parameter "key"?

117
May 07, 2022, at 09:40 AM

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.

Answer 1

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)
          ),
        );
Rent Charter Buses Company
READ ALSO
ffmpeg trim Unable to find a suitable output format

ffmpeg trim Unable to find a suitable output format

As stated in this post i try to split a video using mmpeg, slow down one of the parts and merge them back together

112
Debugging on Android Emulator and Physical Device (Galaxy A10) is crazy slow (MacBook Pro M1)

Debugging on Android Emulator and Physical Device (Galaxy A10) is crazy slow (MacBook Pro M1)

I've got a MacBook Pro M1 (so no access to GenyMotion yet before 33

150
cross compiling ( Android-NDK-Cross-Compile-Build-Automator ) open source utility bindfs for android & other bind mount solutions

cross compiling ( Android-NDK-Cross-Compile-Build-Automator ) open source utility bindfs for android & other bind mount solutions

Background I moved to my new AT&T Samsung phoneunfortunately this is is at Android 10 with selinux enforced there is no way I can change it to permissive and anyway with the proven insecurity it is not worth doing it

130
Android Studio - Open DatePickerDialog from an AppCompatDialog

Android Studio - Open DatePickerDialog from an AppCompatDialog

i want to open a DatePickerDialog from an AppCompatDialog

103