skip to Main Content

Does anyone can help my problem ?

I have a Flutter script below :
ListTile(
title: const Text("Change Password"),
trailing: const Icon(Icons.lock),
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ChangePassword(
value: value, key: null,
)));
},
),

that script is calling the routine below :

class ChangePassword extends StatefulWidget { List value; ChangePassword({required Key key, required this.value}) : super(key: key);

And i’ve got an error message :
"The argument type ‘Null’ can’t be assigned to the parameter type ‘Key’"

how do i solve my problem ?

Thanks in advance,

Tono.

i don’t have any idea….

3

Answers


  1. You should do the key parameter is nullable, like this:

    class ChangePassword extends StatefulWidget { List value; ChangePassword({Key? key, required this.value}) : super(key: key);

    Login or Signup to reply.
  2. You have two options here.

    1. Since you are passing an empty key anyway, just update your code like:
    class ChangePassword extends StatefulWidget {
      final List value;
      const ChangePassword({required this.value, super.key,});
      @override
      State<ChangePassword> createState() => _ChangePasswordState();
    }
    
    1. If you need the Key definitely, you can do something like this (I am updating also your code, so you will dont get any "problems"):
    class ChangePassword extends StatefulWidget {
      final List value;
      const ChangePassword({required this.value, Key? key}): super(key: key);
      @override
      State<ChangePassword> createState() => _ChangePasswordState();
    }
    

    I recommend to use the first one. And I think you have deleted the "?" after key by mistake.

    Login or Signup to reply.
  3. just set your key like this key:Key(”)

    Navigator.of(context).push(MaterialPageRoute( builder: (context) => ChangePassword( value: value, key:Key(""), ))); }, ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search