플러터 key 왜쓰나?

HeejinShin·2023년 2월 27일
0

플러터

목록 보기
6/11

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

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
'''


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('AccountCard'),
),

profile
Studying Go Lang

0개의 댓글