Uranus_ly
Uranus_ly

Reputation: 151

How to use the 'key' in flutter's method?

enter image description here

That method in picture that makes an error, It's called from other file. About that, Flutter required a parameter 'key', so I made it. but makes an error again like below.

Error: The argument type 'Null' can't be assigned to the parameter type 'Key'.

Conclusively what's after 'key:' instead of null?

'''

SavingAccountCard(
                  color: Color(0xffF1A8AF), key: null,

'''

Upvotes: 1

Views: 875

Answers (1)

Dániel Rózsa
Dániel Rózsa

Reputation: 535

Key is a unique identifier of the widget.
There are different types of keys:

  • ValueKey
  • ObjectKey
  • UniqueKey
  • GlobalKey

You may be able to remove the required Key from your class, but if it's required and used there you can just use ValueKey('someUniqueIdByYou').
so the code would be:

SavingAccountCard(
  color: Color(0xffF1A8AF), 
  key: ValueKey<String>('AccountCard'),
),

Upvotes: 2

Related Questions