Bik*_*ram 25
我在 Flutter 2.0.0 中添加了这个功能。确保您使用的 Flutter SDK 版本 >= 2.0.0 才能使用它。
只需在 Scaffold 中使用回调即可
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
drawer: NavDrawer(),
onDrawerChanged: (isOpen) {
// write your callback implementation here
print('drawer callback isOpen=$isOpen');
},
endDrawer: NavDrawerEnd(),
onEndDrawerChanged: (isOpen) {
// write your callback implementation here
print('end drawer callback isOpen=$isOpen');
},
body:
...
Run Code Online (Sandbox Code Playgroud)
Pull 请求合并到 2.0.0:https ://github.com/flutter/flutter/pull/67249
快乐编码!
声明一个GlobalKey来引用您的抽屉:
GlobalKey _drawerKey = GlobalKey();
Run Code Online (Sandbox Code Playgroud)
将钥匙放入抽屉中:
drawer: Drawer(
key: _drawerKey,
Run Code Online (Sandbox Code Playgroud)
检查抽屉是否可见:
final RenderBox box = _drawerKey.currentContext?.findRenderObject();
if (box != null){
//is visible
} else {
//not visible
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
632 次 |
| 最近记录: |