Flutter 如何从底部导航栏项打开其他.dart活动?

Flutter 如何从底部导航栏项打开其他.dart活动?,flutter,flutter-layout,Flutter,Flutter Layout,我已经用颤振实现了下面的底部导航栏 import 'package:flutter/material.dart'; class Test extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return new Scaffold( bottomNavigationBar: new BottomNavigationBar( it

我已经用颤振实现了下面的底部导航栏

import 'package:flutter/material.dart';

class Test extends StatelessWidget  {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
    bottomNavigationBar: new BottomNavigationBar(
        items: [
          new BottomNavigationBarItem(
              icon: new Icon(Icons.add),
              title: new Text("trends")
          ),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.location_on),
              title: new Text("feed")
          ),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.people),
              title: new Text("community")
          )
        ]
    )
);}}
如何使每个
BottomNavigationBar
项目上的
onTap
打开新的
.dart
类?
我尝试过使用选项卡的
选项卡视图
,但不知道如何处理底部导航栏。

您可以这样做

导入“包装:颤振/材料.省道”;
类测试扩展了StatefulWidget{
@凌驾
TestState createState(){
返回新的TestState();
}
}
类TestState扩展了状态{
int _currentIndex=0;
@凌驾
小部件构建(构建上下文){
归还新脚手架(
bottomNavigationBar:新的bottomNavigationBar(
currentIndex:_currentIndex,
onTap:(newIndex)=>setState((){{u currentIndex=newIndex;}),
项目:[
新海底导航气压计(
图标:新图标(Icons.add),
标题:新文本(“趋势”)
),
新海底导航气压计(
图标:新图标(图标位置打开),
标题:新文本(“提要”)
),
新海底导航气压计(
图标:新图标(Icons.people),
标题:新文本(“社区”)
),
],
),
正文:新IndexedStack(
索引:_currentIndex,
儿童:[
新建YourCustomTrendsWidget(),
新建YourCustomFeedWidget(),
新建YourCustomCommunityWidget(),
],
),
);
}
}

你可以这样做

导入“包装:颤振/材料.省道”;
类测试扩展了StatefulWidget{
@凌驾
TestState createState(){
返回新的TestState();
}
}
类TestState扩展了状态{
int _currentIndex=0;
@凌驾
小部件构建(构建上下文){
归还新脚手架(
bottomNavigationBar:新的bottomNavigationBar(
currentIndex:_currentIndex,
onTap:(newIndex)=>setState((){{u currentIndex=newIndex;}),
项目:[
新海底导航气压计(
图标:新图标(Icons.add),
标题:新文本(“趋势”)
),
新海底导航气压计(
图标:新图标(图标位置打开),
标题:新文本(“提要”)
),
新海底导航气压计(
图标:新图标(Icons.people),
标题:新文本(“社区”)
),
],
),
正文:新IndexedStack(
索引:_currentIndex,
儿童:[
新建YourCustomTrendsWidget(),
新建YourCustomFeedWidget(),
新建YourCustomCommunityWidget(),
],
),
);
}
}

谢谢。工作得很有魅力。:)与PageStorageKey不同,StackedIndex小部件最适合在使用BottomNavBar时保持bottomNavItem的状态。干得好您好,假设我有一个登录页面,在经过身份验证后,它会显示一个底部导航栏,加载几个页面,这与其建议的解决方案相同。我的问题是,在bottomnavbar显示的页面中,我有一个用于注销的按钮,我尝试的所有操作都会导致登录页面被加载,但会同时加载bottomnavbar。有什么建议吗?他们的github就是这样的例子吗?@RussellHarrower也许这有帮助:谢谢。工作得很有魅力。:)与PageStorageKey不同,StackedIndex小部件最适合在使用BottomNavBar时保持bottomNavItem的状态。干得好您好,假设我有一个登录页面,在经过身份验证后,它会显示一个底部导航栏,加载几个页面,这与其建议的解决方案相同。我的问题是,在bottomnavbar显示的页面中,我有一个用于注销的按钮,我尝试的所有操作都会导致登录页面被加载,但会同时加载bottomnavbar。有什么建议吗?他们的github就是这样的一个例子吗?@RussellHarrower也许这有帮助: