【发布时间】:2021-07-08 14:32:13
【问题描述】:
我对颤振/飞镖相对较新,我想在用户点击我的自定义应用栏上的汉堡菜单时以编程方式打开一个抽屉。但是,在执行以下代码后,
profile_page.dart
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverAppBar(
floating: false,
pinned: true,
primary: true,
flexibleSpace: TopBar(
title: "Profile",
hasBackButton: false,
hasHamburgerMenu: true,
openDrawer: () {
Scaffold.of(context).openEndDrawer();
},
),
collapsedHeight: 180,
expandedHeight: 180,
backgroundColor: Color.fromRGBO(250, 250, 250, 1),
)
],
)),
endDrawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
DrawerHeader(
decoration: BoxDecoration(color: Theme.of(context).accentColor),
child: Text("Drawer Header")),
ListTile(
title: Text("Test 1"),
onTap: () {
Navigator.pop(context);
},
)
],
)));
}
top_bar.dart
Widget build(BuildContext context) {
return Container(
child: Padding(
padding: const EdgeInsets.only(top: 25.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
if (hasBackButton ?? true)
Container(
child: GestureDetector(
child: Image(
image: AssetImage("assets/images/previous.png"),
color: Theme.of(context).accentColor,
width: 25,
height: 25),
onTap: onPressed,
),
)
else
Text(""),
Text(""),
Text(title ?? "Top Bar",
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.w800,
color: Theme.of(context).accentColor)),
Text(""),
if (hasHamburgerMenu ?? false)
InkWell(
onTap: openDrawer, child: Icon(Icons.menu))
else
Text("")
],
),
),
);
}
我的界面显示openEndDrawer() 被标记为“虚构的”AppBar 汉堡菜单按钮,而不是我的汉堡菜单图标,如下面的屏幕截图所示。
响应onTap() 的白色汉堡菜单根本没有在我的应用程序中编码。
很高兴我能在这方面得到任何形式的帮助。谢谢!
【问题讨论】:
标签: flutter dart navigation-drawer flutter-appbar