[英]Flutter - Call onTap from another widget
I have a convex bottom bar and the last tab is a Menu that opens a drawer when clicked.我有一个凸底栏,最后一个选项卡是一个菜单,单击时会打开一个抽屉。 But I'm having troubles when the drawer is closed.但是当抽屉关闭时我遇到了麻烦。 As the tab Menu only opens a drawer I wish it could return to previous tab when drawer closes, but the Menu tab keeps active.由于选项卡菜单仅打开一个抽屉,我希望它可以在抽屉关闭时返回到上一个选项卡,但菜单选项卡保持活动状态。 The tab only changes when it is clicked.该选项卡仅在单击时更改。 So how can I call the onTab property of convex_tab_bar when the drawer is closed?那么如何在抽屉关闭时调用convex_tab_bar的onTab属性呢?
...
return Scaffold(
key: _scaffoldKey,
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text('Drawer Header'),
),
ListTile(
title: const Text('Item 1'),
onTap: () {},
),
],
),
),
onDrawerChanged: (isOpen) {
if (!isOpen) {
setState(() {
_currentOption = _previousOption;
});
changeTab(context, _previousOption);
}
},
body: Container(
child: _currentPage,
),
bottomNavigationBar: StyleProvider(
style: Style(),
child: ConvexAppBar(
style: TabStyle.fixedCircle,
backgroundColor: Colors.white,
color: Colors.grey,
activeColor: _currentOption == 1
? const Color(0xffa98e47)
: const Color(0xff00c9ff),
items: [
TabItem(
icon: const Icon(
ReceivedIcon.receivedIcon,
color: Colors.grey,
size: 12,
),
title: AppLocalizations.of(context)!.received,
activeIcon: const Icon(
ReceivedIcon.receivedIcon,
color: Color(0xff00c9ff),
size: 12,
),
),
TabItem(
icon: const Icon(SentIcon.sentIcon, color: Colors.grey),
title: AppLocalizations.of(context)!.sent,
activeIcon: const Icon(SentIcon.sentIcon, color: Color(0xffa98e47)),
),
const TabItem(
icon: Icon(
Icons.add_rounded,
size: 48,
color: Colors.white,
)
),
TabItem(
icon: Icons.notifications,
title: AppLocalizations.of(context)!.notifications
),
TabItem(
icon: Icons.menu,
title: AppLocalizations.of(context)!.menu
),
],
onTap: (int i) {
changeTab(context, i);
},
),
),
);
create a function onTapHandler
in your class... put the referece on your ConvexAppBar(onTap:onTapHandler...) and now you are able to call the onTapHandler in your onDrawerChanged
handler在您的 class 中创建一个 function onTapHandler
... 将参考放在您的 ConvexAppBar(onTap:onTapHandler...) 上,现在您可以在onDrawerChanged
处理程序中调用 onTapHandler
try this https://github.com/hacktons/convex_bottom_bar/blob/master/doc/issue-change-active-tab-index.md (Change active tab index programmaticlly)试试这个https://github.com/hacktons/convex_bottom_bar/blob/master/doc/issue-change-active-tab-index.md (以编程方式更改活动标签索引)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.