Flutter 如何在颤振web中的NavigationRail右侧添加选项卡栏?
我有一个AppBar和一个NavigationRail,我想为NavigationBar中选择的每个选项卡添加不同的选项卡栏,但是当我向AppBar添加一个选项卡栏时,它看起来不太好,它占用了整个选项卡栏的宽度,删除了NavigationRail。此外,我将添加一段代码,以及我所拥有和想要实现的内容的图像Flutter 如何在颤振web中的NavigationRail右侧添加选项卡栏?,flutter,dart,flutter-layout,flutter-web,Flutter,Dart,Flutter Layout,Flutter Web,我有一个AppBar和一个NavigationRail,我想为NavigationBar中选择的每个选项卡添加不同的选项卡栏,但是当我向AppBar添加一个选项卡栏时,它看起来不太好,它占用了整个选项卡栏的宽度,删除了NavigationRail。此外,我将添加一段代码,以及我所拥有和想要实现的内容的图像 import 'package:finnik_admin_mvp/constants.dart'; import 'package:finnik_admin_mvp/pages/views/n
import 'package:finnik_admin_mvp/constants.dart';
import 'package:finnik_admin_mvp/pages/views/news_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class MainPage extends StatefulWidget {
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
int _selectedIndex = 1;
getView() {
switch (_selectedIndex) {
case 1:
{
return NewsView();
}
break;
default:
{
return Expanded(
child: Center(
child: Text('selectedIndex: $_selectedIndex'),
),
);
}
break;
}
}
@override
Widget build(BuildContext context) {
ScreenUtil.init(
context,
height: 1080,
width: 1920,
);
ScreenUtil _su = ScreenUtil();
return Scaffold(
backgroundColor: kPurpuleColor,
appBar: PreferredSize(
preferredSize: Size.fromHeight(
_su.setHeight(102),
),
child: AppBar(
backgroundColor: kPurpuleColor,
leadingWidth: _su.setWidth(180),
actions: [
Container(
margin: EdgeInsets.only(
right: _su.setWidth(8),
),
width: _su.setWidth(150),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: FaIcon(
FontAwesomeIcons.userCircle,
size: _su.setWidth(37.86),
),
onPressed: () {},
),
IconButton(
icon: FaIcon(
FontAwesomeIcons.bars,
size: _su.setWidth(37.86),
),
onPressed: () {},
),
],
),
),
],
leading: Container(
margin: EdgeInsets.only(left: 30),
child: Image.asset(
kLogoSolidPath,
width: _su.setWidth(146),
height: _su.setHeight(66),
),
),
),
),
body: SafeArea(
child: Row(
children: [
Container(
width: 70,
height: MediaQuery.of(context).size.height,
child: NavigationRail(
minWidth: 50,
backgroundColor: kPurpuleColor,
selectedIconTheme: IconThemeData(
color: kYellowColor,
size: _su.setWidth(
35,
),
),
unselectedIconTheme: IconThemeData(
color: Colors.white,
size: _su.setWidth(
35,
),
),
elevation: 3,
destinations: [
NavigationRailDestination(
icon: FaIcon(
FontAwesomeIcons.home,
),
label: Container(),
),
NavigationRailDestination(
icon: FaIcon(
FontAwesomeIcons.newspaper,
),
label: Container(),
),
NavigationRailDestination(
icon: FaIcon(
FontAwesomeIcons.userAlt,
),
label: Container(),
),
NavigationRailDestination(
icon: FaIcon(
FontAwesomeIcons.tags,
),
label: Container(),
),
NavigationRailDestination(
icon: FaIcon(
Icons.import_export,
size: 35,
),
label: Container(),
),
NavigationRailDestination(
icon: FaIcon(
FontAwesomeIcons.dollarSign,
),
label: Container(),
),
NavigationRailDestination(
icon: FaIcon(
FontAwesomeIcons.chartLine,
),
label: Container(),
),
NavigationRailDestination(
icon: FaIcon(
FontAwesomeIcons.cog,
),
label: Container(),
),
NavigationRailDestination(
icon: FaIcon(
FontAwesomeIcons.questionCircle,
),
label: Container(),
),
],
labelType: NavigationRailLabelType.all,
selectedIndex: _selectedIndex,
onDestinationSelected: (int index) {
setState(() {
_selectedIndex = index;
});
},
),
),
VerticalDivider(thickness: 2, width: 2),
getView(),
],
)),
);
}
}
import'package:finnik_admin_mvp/constants.dart';
导入“包:finnik_admin_mvp/pages/views/news_view.dart”;
进口“包装:颤振/材料.省道”;
导入“package:flatter_screenutil/flatter_screenutil.dart”;
导入“package:font_awesome_flatter/font_awesome_flatter.dart”;
类MainPage扩展了StatefulWidget{
@凌驾
_MainPageState createState()=>\u MainPageState();
}
类_MainPageState扩展状态{
int _selectedIndex=1;
getView(){
开关(_selectedIndex){
案例1:
{
返回NewsView();
}
打破
违约:
{
扩大回报(
儿童:中心(
子项:文本('selectedIndex:$\u selectedIndex'),
),
);
}
打破
}
}
@凌驾
小部件构建(构建上下文){
ScreenUtil.init(
上下文
身高:1080,
宽度:1920,
);
ScreenUtil_su=ScreenUtil();
返回脚手架(
背景颜色:kPurpuleColor,
appBar:首选大小(
首选大小:Size.fromHeight(
_su.设定高度(102),
),
孩子:AppBar(
背景颜色:kPurpuleColor,
引线宽度:_su.setWidth(180),
行动:[
容器(
页边距:仅限边距(
右:_su.setWidth(8),
),
宽度:设置宽度(150),
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
图标按钮(
图标:FaIcon(
FontAwesomeIcons.userCircle,
尺寸:_su.设置宽度(37.86),
),
按下:(){},
),
图标按钮(
图标:FaIcon(
FontAwesomeIcons.bar,
尺寸:_su.设置宽度(37.86),
),
按下:(){},
),
],
),
),
],
领先:集装箱(
页边距:仅限边集(左:30),
子:Image.asset(
kLogoSolidPath,
宽度:_su.setWidth(146),
高度:设置高度(66),
),
),
),
),
正文:安全区(
孩子:排(
儿童:[
容器(
宽度:70,
高度:MediaQuery.of(context).size.height,
孩子:导航轨道(
最小宽度:50,
背景颜色:kPurpuleColor,
选择主题:图标主题数据(
颜色:kYellowColor,
尺寸:_su.setWidth(
35,
),
),
未选择的主题:IconThemeData(
颜色:颜色,白色,
尺寸:_su.setWidth(
35,
),
),
标高:3,
目的地:[
导航铁路目的地(
图标:FaIcon(
Fontawe.home,
),
标签:Container(),
),
导航铁路目的地(
图标:FaIcon(
Fontawes.报纸,
),
标签:Container(),
),
导航铁路目的地(
图标:FaIcon(
FontAwesomeIcons.userAlt,
),
标签:Container(),
),
导航铁路目的地(
图标:FaIcon(
FontAwesomeIcons.tags,
),
标签:Container(),
),
导航铁路目的地(
图标:FaIcon(
Icons.import\u export,
尺码:35,
),
标签:Container(),
),
导航铁路目的地(
图标:FaIcon(
FontAwesomeIcons.dollarSign,
),
标签:Container(),
),
导航铁路目的地(
图标:FaIcon(
FontAwesomeIcons.chartLine,
),
标签:Container(),
),
导航铁路目的地(
图标:FaIcon(
FontAwesomeIcons.cog,
),
标签:Container(),
),
导航铁路目的地(
图标:FaIcon(
FontAwesomeIcons.questionCircle,
),
标签:Container(),
),
],
labelType:NavigationRailLabelType.all,
selectedIndex:\u selectedIndex,
onDestinationSelected:(int索引){
设置状态(){
_selectedIndex=索引;
});
},
),
),
垂直分隔带(厚度:2,宽度:2),
getView(),
],
)),
);
}
}
我现在所拥有的:
我想要达到的目标: