Flutter 颤振包谷歌导航栏-3个标签,而不是4个
我正在使用flifter制作一个应用程序,非常喜欢这个软件包。我已经安装并运行了它,但我不知道如何使导航栏3个选项卡而不是4个 这是我的密码:Flutter 颤振包谷歌导航栏-3个标签,而不是4个,flutter,dart,navbar,Flutter,Dart,Navbar,我正在使用flifter制作一个应用程序,非常喜欢这个软件包。我已经安装并运行了它,但我不知道如何使导航栏3个选项卡而不是4个 这是我的密码: class Example extends StatefulWidget { @override _ExampleState createState() => _ExampleState(); } class _ExampleState extends State<Example> { int _selectedIndex
class Example extends StatefulWidget {
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Reviews',
style: optionStyle,
),
Text(
'Index 1: Shop',
style: optionStyle,
),
Text(
'Index 2: Account',
style: optionStyle,
),
Text(
'Non existent',
style: optionStyle,
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Mijnmedicijn.nl'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: Container(
decoration: BoxDecoration(color: Colors.white, boxShadow: [
BoxShadow(blurRadius: 20, color: Colors.black.withOpacity(.1))
]),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 8),
child: GNav(
gap: 8,
activeColor: Colors.white,
iconSize: 24,
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 5),
duration: Duration(milliseconds: 800),
tabBackgroundColor: Colors.grey[800],
tabs: [
GButton(
icon: LineIcons.home,
text: 'Home',
),
GButton(
icon: LineIcons.heart_o,
text: 'Likes',
),
GButton(
icon: LineIcons.search,
text: 'Account',
),
GButton(
icon: LineIcons.user,
text: 'Profile',
),
],
selectedIndex: _selectedIndex,
onTabChange: (index) {
setState(() {
_selectedIndex = index;
});
}),
),
),
),
);
}
}
类示例扩展了StatefulWidget{
@凌驾
_ExampleState createState()=>\u ExampleState();
}
类_示例状态扩展状态{
int _selectedIndex=0;
静态常量文本样式选项样式=
TextStyle(fontSize:30,fontWeight:fontWeight.bold);
静态常量列表_widgetOptions=[
正文(
“索引0:评论”,
样式:可选样式,
),
正文(
"索引1:店铺",,
样式:可选样式,
),
正文(
"索引2:帐户",,
样式:可选样式,
),
正文(
“不存在”,
样式:可选样式,
),
];
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:常量文本('Mijnmedicijn.nl'),
),
正文:中(
子项:_widgetOptions.elementAt(_selectedIndex),
),
底部导航栏:容器(
装饰:框装饰(颜色:Colors.white,框阴影:[
BoxShadow(模糊半径:20,颜色:Colors.black.withOpacity(.1))
]),
儿童:安全区(
孩子:填充(
填充:常量边集。对称(水平:15.0,垂直:8),
孩子:GNav(
差距:8,
activeColor:Colors.white,
iconSize:24,
填充:边缘组。对称(水平:20,垂直:5),
持续时间:持续时间(毫秒:800),
tabBackgroundColor:颜色.灰色[800],
选项卡:[
钮扣(
图标:LineIcons.home,
文本:“主页”,
),
钮扣(
图标:LineIcons.heart\u o,
文字:“喜欢”,
),
钮扣(
图标:LineIcons.search,
文本:“帐户”,
),
钮扣(
图标:LineIcons.user,
文本:“配置文件”,
),
],
selectedIndex:\u selectedIndex,
onTabChange:(索引){
设置状态(){
_selectedIndex=索引;
});
}),
),
),
),
);
}
}
我尝试删除其中一个文本(“不存在”)和最后一个GButton,但没有成功(这给了我一个范围错误)
这是可能的,因为在Github上它显示了一个带有3个选项卡的示例
有人知道怎么做吗?我试过你的代码,删除了最后一个Text()和最后一个GButton(),看起来效果不错 以下是我尝试的代码:
class Example extends StatefulWidget {
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Reviews',
style: optionStyle,
),
Text(
'Index 1: Shop',
style: optionStyle,
),
Text(
'Index 2: Account',
style: optionStyle,
)
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Mijnmedicijn.nl'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: Container(
decoration: BoxDecoration(color: Colors.white, boxShadow: [
BoxShadow(blurRadius: 20, color: Colors.black.withOpacity(.1))
]),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 8),
child: GNav(
gap: 8,
activeColor: Colors.white,
iconSize: 24,
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 5),
duration: Duration(milliseconds: 800),
tabBackgroundColor: Colors.grey[800],
tabs: [
GButton(
icon: LineIcons.home,
text: 'Home',
),
GButton(
icon: LineIcons.heart_o,
text: 'Likes',
),
GButton(
icon: LineIcons.search,
text: 'Account',
)
],
selectedIndex: _selectedIndex,
onTabChange: (index) {
setState(() {
_selectedIndex = index;
});
}),
),
),
),
);
}
}
类示例扩展了StatefulWidget{
@凌驾
_ExampleState createState()=>\u ExampleState();
}
类_示例状态扩展状态{
int _selectedIndex=0;
静态常量文本样式选项样式=
TextStyle(fontSize:30,fontWeight:fontWeight.bold);
静态常量列表_widgetOptions=[
正文(
“索引0:评论”,
样式:可选样式,
),
正文(
"索引1:店铺",,
样式:可选样式,
),
正文(
"索引2:帐户",,
样式:可选样式,
)
];
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:常量文本('Mijnmedicijn.nl'),
),
正文:中(
子项:_widgetOptions.elementAt(_selectedIndex),
),
底部导航栏:容器(
装饰:框装饰(颜色:Colors.white,框阴影:[
BoxShadow(模糊半径:20,颜色:Colors.black.withOpacity(.1))
]),
儿童:安全区(
孩子:填充(
填充:常量边集。对称(水平:15.0,垂直:8),
孩子:GNav(
差距:8,
activeColor:Colors.white,
iconSize:24,
填充:边缘组。对称(水平:20,垂直:5),
持续时间:持续时间(毫秒:800),
tabBackgroundColor:颜色.灰色[800],
选项卡:[
钮扣(
图标:LineIcons.home,
文本:“主页”,
),
钮扣(
图标:LineIcons.heart\u o,
文字:“喜欢”,
),
钮扣(
图标:LineIcons.search,
text:'帐户',
)
],
selectedIndex:\u selectedIndex,
onTabChange:(索引){
设置状态(){
_selectedIndex=索引;
});
}),
),
),
),
);
}
}
希望有帮助 你的代码成功了!我真的不知道为什么我的不工作,然后(也许我还删除了其他东西或东西)。