Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用底部导航在颤振中在省道文件之间切换_Android_Flutter_Dart_Bottomnavigationview_Tap - Fatal编程技术网

Android 使用底部导航在颤振中在省道文件之间切换

Android 使用底部导航在颤振中在省道文件之间切换,android,flutter,dart,bottomnavigationview,tap,Android,Flutter,Dart,Bottomnavigationview,Tap,我用这个示例代码设计了一个底部导航栏,现在它工作了。当我点击每个项目时,我想显示不同的省道文件,默认情况下显示第一页,但在这个代码中,我使用了任何页面的显示按钮。现在我想知道我该怎么做 谢谢大家 代码如下: import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:store/pages/category.da

我用这个示例代码设计了一个底部导航栏,现在它工作了。当我点击每个项目时,我想显示不同的省道文件,默认情况下显示第一页,但在这个代码中,我使用了任何页面的显示按钮。现在我想知道我该怎么做

谢谢大家

代码如下:

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:store/pages/category.dart';
import 'package:store/pages/index_shop.dart'; 


void main() {
 runApp(
 MaterialApp(localizationsDelegates: [
  GlobalMaterialLocalizations.delegate,
  GlobalWidgetsLocalizations.delegate,
], supportedLocales: [
  Locale("en", "US"),
  Locale("fa", "IR"), // OR Locale('ar', 'AE') OR Other RTL locales
], debugShowCheckedModeBanner: false, home: Home()),
);
}

class Home extends StatefulWidget {
 @override
 State<StatefulWidget> createState() {
  return HomeState();
 }
 }

 class HomeState extends State<Home> {
   bool clickedCentreFAB = false; 
   int selectedIndex = 0; //to handle which item is currently selected in the bottom app bar
   String text = "Home";

  void updateTabSelection(int index, String buttonText) {
    setState(() {
    selectedIndex = index;
    text = buttonText;
    });
    }

   @override
   Widget build(BuildContext context) {
    return Scaffold(
     body: Stack(
     children: <Widget>[
       Align(
        alignment: FractionalOffset.center,

        child: RaisedButton(
          child: Text(text),
          onPressed: () {},
        ),
      ),

      Align(
        alignment: FractionalOffset.bottomCenter,
        child: AnimatedContainer(
          duration: Duration(milliseconds: 250),
          //if clickedCentreFAB == true, the first parameter is used. If it's false, the second.
          height:
          clickedCentreFAB ? MediaQuery.of(context).size.height : 10.0,
          width: clickedCentreFAB ? MediaQuery.of(context).size.height : 10.0,
          decoration: BoxDecoration(
              borderRadius:
              BorderRadius.circular(clickedCentreFAB ? 0.0 : 300.0),
              color: Colors.blue),
            ),
            )
            ],
            ),
            floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, 
            floatingActionButton: FloatingActionButton(
             onPressed: () {
             setState(() {
             clickedCentreFAB = !clickedCentreFAB; //to update the animated container
            });
             },
            tooltip: "Centre FAB",
            child: Container(
            margin: EdgeInsets.all(15.0),
            child: Icon(Icons.live_tv),
             ),
            elevation: 4.0,
             ),
             bottomNavigationBar: BottomAppBar(
             child: Container(
              margin: EdgeInsets.only(left: 12.0, right: 12.0),
            child: Row(
            mainAxisSize: MainAxisSize.max,
             mainAxisAlignment: MainAxisAlignment.spaceBetween,
             children: <Widget>[
           IconButton(
            //update the bottom app bar view each time an item is clicked
            onPressed: () {
              updateTabSelection(0, "Home");
            },
            iconSize: 27.0,
            icon: Icon(
              Icons.shopping_cart,
              //darken the icon if it is selected or else give it a different color
              color: selectedIndex == 0
                  ? Colors.blue.shade900
                  : Colors.grey.shade400,
            ),
          ),
          IconButton(
            onPressed: () {
              updateTabSelection(1, "Outgoing");
            },
            iconSize: 27.0,
            icon: Icon(
              Icons.dashboard,
              color: selectedIndex == 1
                  ? Colors.blue.shade900
                  : Colors.grey.shade400,
            ),
          ),
          //to leave space in between the bottom app bar items and below the FAB
          SizedBox(
            width: 50.0,
          ),
          IconButton(
            onPressed: () {
              updateTabSelection(2, "Incoming");
            },
            iconSize: 27.0,
            icon: Icon(
              Icons.shopping_basket,
              color: selectedIndex == 2
                  ? Colors.blue.shade900
                  : Colors.grey.shade400,
            ),
          ),
          IconButton(
            onPressed: () {
              updateTabSelection(3, "Settings");
            },
            iconSize: 27.0,
            icon: Icon(
              Icons.person,
              color: selectedIndex == 3
                  ? Colors.blue.shade900
                  : Colors.grey.shade400,
            ),
          ),
        ],
      ),
    ),
    //to add a space between the FAB and BottomAppBar
    shape: CircularNotchedRectangle(),
    //color of the BottomAppBar
    color: Colors.white,
  ),
);
 }
  }
导入“包装:颤振/材料.省道”;
导入“package:flatter_本地化/flatter_本地化.dart”;
导入“package:store/pages/category.dart”;
导入“package:store/pages/index_shop.dart”;
void main(){
runApp(
MaterialApp(本地化数据包:[
GlobalMaterialAllocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],支持的地区:[
地区(“欧洲”、“美国”),
语言环境(“fa”、“IR”)、//或语言环境(“ar”、“AE”)或其他RTL语言环境
],debugShowCheckedModeBanner:false,home:home()),
);
}
类Home扩展了StatefulWidget{
@凌驾
状态createState(){
返回家园();
}
}
类HomeState扩展到State{
bool clickedCentreFAB=false;
int selectedIndex=0;//处理当前在底部应用程序栏中选择的项目
String text=“Home”;
void updateTableSelection(int索引,字符串buttonText){
设置状态(){
selectedIndex=索引;
文本=按钮文本;
});
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:堆栈(
儿童:[
对齐(
对齐:分馏loffset.center,
孩子:升起按钮(
子:文本(Text),
按下:(){},
),
),
对齐(
对齐:分馏Loffset.bottomCenter,
子:动画容器(
持续时间:持续时间(毫秒:250),
//如果clickedCentreFAB==true,则使用第一个参数。如果为false,则使用第二个参数。
高度:
clickedCentreFAB?MediaQuery.of(上下文)。size.height:10.0,
宽度:clickedCentreFAB?MediaQuery.of(上下文)。大小。高度:10.0,
装饰:盒子装饰(
边界半径:
边界半径。圆形(单击中心半径?0.0:300.0),
颜色:颜色。蓝色),
),
)
],
),
floatingActionButtonLocation:floatingActionButtonLocation.centerDocked,
浮动操作按钮:浮动操作按钮(
已按下:(){
设置状态(){
clickedCentreFAB=!clickedCentreFAB;//更新动画容器
});
},
工具提示:“中心工厂”,
子:容器(
边距:所有边缘集(15.0),
子:图标(图标。直播电视),
),
标高:4.0,
),
bottomNavigationBar:BottomAppBar(
子:容器(
边距:仅限边集(左:12.0,右:12.0),
孩子:排(
mainAxisSize:mainAxisSize.max,
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
图标按钮(
//每次单击项目时更新底部应用程序栏视图
已按下:(){
UpdateTableSelection(0,“主页”);
},
iconSize:27.0,
图标:图标(
图标。购物车,
//如果选中图标,则将其变暗,或者为其指定不同的颜色
颜色:selectedIndex==0
?颜色。蓝色。阴影900
:Colors.grey.shade400,
),
),
图标按钮(
已按下:(){
更新选举(1,“离任”);
},
iconSize:27.0,
图标:图标(
图标。仪表板,
颜色:selectedIndex==1
?颜色。蓝色。阴影900
:Colors.grey.shade400,
),
),
//在底部应用程序栏项目之间和工厂下方留出空间
大小盒子(
宽度:50.0,
),
图标按钮(
已按下:(){
UpdateTableSelection(2,“传入”);
},
iconSize:27.0,
图标:图标(
图标、购物篮、,
颜色:selectedIndex==2
?颜色。蓝色。阴影900
:Colors.grey.shade400,
),
),
图标按钮(
已按下:(){
更新BSelection(3,“设置”);
},
iconSize:27.0,
图标:图标(
一个人,
颜色:selectedIndex==3
?颜色。蓝色。阴影900
:Colors.grey.shade400,
),
),
],
),
),
//在FAB和BottomAppBar之间添加空格的步骤
形状:CircularNotchedRectangle(),
//底部AppBar的颜色
颜色:颜色,白色,
),
);
}
}
您可以在图标按钮的“按下”方法上使用导航器 步骤1在MaterialApp上创建OnGeneratorOute

return MaterialApp(
debugShowCheckedModeBanner:false,
标题:应用程序名称,
主页:GetStarted(),
onGenerateRoute:(路由设置){
开关(设置.名称){
案例“类别”:
返回CupertinoPageRoute(
生成器:(BuildContext上下文){
退货类别();
},
设置:设置,
);
打破
案例“索引”:
返回CupertinoPageRoute(
生成器:(BuildContext上下文){
返回索引();
},
设置:设置);
打破
}
}
);
步骤2在IConButtonPressed方法中添加导航

Navigator.of(context.pushNamed(“category”);