flutter - 抽屉没有出现在 SliverAppBar
问题描述
我想Drawer
在我的代码里面添加一个,里面SliverAppBar
没有任何错误,但是当我运行代码时,抽屉没有出现。
这是我的代码
body: CustomScrollView(
slivers: <Widget>[
SliverLayoutBuilder(
builder: (BuildContext context, constraints) {
final scrolled = constraints.scrollOffset > 50;
final scrolledicon = constraints.scrollOffset > 0;
return SliverAppBar(
expandedHeight: 20,
toolbarHeight: 65,
leading: Padding(
padding: const EdgeInsets.only(top: 2),
child: Icon(DBIcons.logo, color: Colors.red, size: 50),
),
actions: [
Padding(
padding: const EdgeInsets.all(10),
child: IconButton(
icon: Icon(Icons.menu),
color: scrolledicon ? Colors.white : Colors.black,
onPressed: (){
Drawer(
child: Center(
child: Text('This is Drawer'),
),
);
},
),
),
],
backgroundColor: scrolled ? Colors.black : Colors.transparent,
elevation: 0,
pinned: true,
);
},
),
解决方案
请看这里。
在您的脚手架中,您必须注册一个抽屉
Scaffold(
...
drawer: Drawer(child: Center(
child: Text('This is Drawer'),
),
...
);
使用onPressed您将打开抽屉的请求发送到脚手架:
onPressed: () => Scaffold.of(context).openDrawer(),
推荐阅读
- reactjs - 在组件渲染之前未填充 Redux Store
- ruby - 隐式接收器
- node.js - 浏览器重新加载后,服务器端的 React redux-saga 不采取行动
- arima - ARIMA 模型中的错误
- linkedin - LinkedIn API V1 - 发布到 Companies/{companyId}/shares 时收到“未经授权的请求”
- angular - 子组件隐藏时执行子组件功能
- azure-sqldw - Azure SQL 数据仓库中返回表类型的函数是否有替代方法?
- c# - Xamarin.IOS:无法解析引用 (System.Threading.Tasks.Extension.dll)
- r - R中的“合并”用NA替换实际值
- inno-setup - 设置完成后打开预定义的 url