2022-03-01 GlobalKey的使用

2022-03-01  本文已影响0人  Jean_Lina
(1) 定义GlobalKey
final GlobalKey<_UserInfoItemState> _globalKey = GlobalKey();

(2) 绑定key
body: UserInfoItem(key: _globalKey),

(3)使用GlobalKey访问currentState中的变量
final String? userName = _globalKey.currentState?.widget.userName;             
final String? userPhone = _globalKey.currentState?.userPhone;
上一篇 下一篇

猜你喜欢

热点阅读