【发布时间】:2020-03-11 19:13:39
【问题描述】:
我想从其他页面导航到页面上的第二个底部项目。
这里的父级是BottomNavigationBar,我要配置它来改变页面(我在Provider中为它定义了一个键,以便从其他页面访问它)。
List<Widget> pages = new List<Widget>();
BottomNavigationBar bottomNavigationBar;
updateList(){
pages.addAll({
Dashboard(),
AllServices(),
Account(),
Charge(),
});
}
int _selectedIndex = 0;
Widget _bottomNavigationBar(int selectedIndex,key) {
return BottomNavigationBar(
key: key,
onTap: (int index) => setState(() => _selectedIndex = index),
currentIndex: selectedIndex,
type: BottomNavigationBarType.fixed,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text("A page"),
),
BottomNavigationBarItem(
icon: new Icon(Icons.location_on),
title: new Text("B page")
),
BottomNavigationBarItem(
icon: new Icon(Icons.store),
title: new Text("C page")
),
BottomNavigationBarItem(
icon: new Icon(Icons.person),
title:new Text("D page")
),
],
);
}
@override
void initState() {
// TODO: implement initState
super.initState();
updateList();
}
@override
Widget build(BuildContext context) {
final globalKeyForBottomNavigate = Provider.of<Controller>(context, listen: false).bottomNavigate;
return Scaffold(
bottomNavigationBar: _bottomNavigationBar(_selectedIndex,globalKeyForBottomNavigate),
body: pages[_selectedIndex],
);
}
而孩子是Page A、B、C、D。现在从页面A I导航到页面F。然后如果触发了一个动作,我想导航到页面B,但我的解决方案是更改BottomNavigationBar的索引页面F,然后导航到页面A。它可以工作,但不直接导航到页面B和BottomNavigationBar的内容。在我的解决方案中,我说好的首先更改BottomNavigationBar的索引,然后转到最后一页(这里是页面A),但是如您所见,我不知道如何直接导航到页面B。这是页面F的代码.
onTap: (){
var bottomKey=Provider.of<Controller>(context, listen: false).bottomNavigate;
final BottomNavigationBar navigationBar = bottomKey.currentWidget;
navigationBar.onTap(1);
Navigator.pop(context);
},
【问题讨论】:
标签: flutter flutter-navigation