美文网首页
2022-03-01 GlobalKey的使用

2022-03-01 GlobalKey的使用

作者: Jean_Lina | 来源:发表于2022-03-01 16:20 被阅读0次
(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;

相关文章

网友评论

      本文标题:2022-03-01 GlobalKey的使用

      本文链接:https://www.haomeiwen.com/subject/ytmdrrtx.html