2022-03-01 GlobalKey的使用

(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的使用)