gpt4 book ai didi

dart - 如何在 Flutter 中使抽屉按钮不可点击

转载 作者:IT王子 更新时间:2023-10-29 07:12:01 26 4
gpt4 key购买 nike

当我的应用程序启动时,一些数据会在后台加载我不希望用户在那个时候点击Drawer 图标,所以我做了这样的事情。

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Title'),
),
drawer: _isLoading ? null : HomeDrawer(),
body: _isLoading ? CircularProgressIndicator() : _body(),
);
}

在这种情况下,当应用程序加载时,抽屉按钮不可见

enter image description here

加载后,按钮返回。

enter image description here

我想要的是抽屉按钮在加载状态下应可见,但不应可点击。

最佳答案

你可以试试这个。

bool _isLoading = false;
GlobalKey<ScaffoldState> _key = GlobalKey();

@override
Widget build(BuildContext context) {
return Scaffold(
key: _key,
appBar: AppBar(
title: Text("App"),
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: _isLoading ? null : () => _key.currentState.openDrawer(),
),
),
drawer: YourDrawer(),
);
}

关于dart - 如何在 Flutter 中使抽屉按钮不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55559266/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com