1分钟
07 GlobalKey
在Flutter中,要主动改变子控件的状态,还可以使用 GlobalKey
。 比如你需要主动调用 RefreshIndicator
显示刷新状态,如下代码所示。
GlobalKey<RefreshIndicatorState> refreshIndicatorKey;
showForRefresh() {
///显示刷新
refreshIndicatorKey.currentState.show();
}
@override
Widget build(BuildContext context) {
refreshIndicatorKey = new GlobalKey<RefreshIndicatorState>();
return new RefreshIndicator(
key: refreshIndicatorKey,
onRefresh: onRefresh,
child: new ListView.builder(
///·····
),
);
}
学员评价