我正在制作一个Flutter应用程序,我需要能够通过点击BottomNavigationBarItem来打开抽屉。有什么办法吗?
UX设计人员将抽屉菜单图标放在底部导航栏中的索引0处。我试图在Flutter文档中找到答案,但没有找到任何相关内容。实际上,我找到了一种以编程方式打开它的方法(如下所示),但是在我的情况下,它却无法正常工作。
class _HomeState extends State<Home> {
int _currentIndex = 1; // 0 = menu
final List<Widget> _children = [
PlaceholderWidget(Colors.deepPurple),
PlaceholderWidget(Colors.white),
DiagnosisWidget(),
FindUsWidget(),
];
_navItem(String text, IconData icon) {
return BottomNavigationBarItem(
/* Building Bottom nav item */
);
}
void onTabTapped(int index) {
setState(() {
if(index == 0) {
Scaffold.of(context).openDrawer(); // This is what I've tried
}
else {
_currentIndex = index;
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(
child: MyDrawer(),
),
body: _children[_currentIndex], …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Flutter应用中为地图标记设置自定义图标。由于BitmapDescriptor.fromAsset()已弃用,因此我正在寻找如何使用BitmapDescriptor.fromAssetImage()。
我没有找到关于此的任何文档或Stackoverflow问题。
这是我创建它的当前方式(没有自定义图像):
Marker(
markerId: MarkerId(pos.toString()),
position: pos,
infoWindow: InfoWindow(
title: store['store_name'],
snippet: '',
),
icon: BitmapDescriptor.defaultMarker));
Run Code Online (Sandbox Code Playgroud)