Android Can';t结合底部导航栏显示立柱(颤振1.9.1)
因此,我正在构建一个颤振应用程序,其中有四个不同的功能。 我非常喜欢底部导航栏的外观和图标等等,所以我决定选择这个选项。 我实现它的方式如下:我声明了一个Android Can';t结合底部导航栏显示立柱(颤振1.9.1),android,flutter,flutter-layout,Android,Flutter,Flutter Layout,因此,我正在构建一个颤振应用程序,其中有四个不同的功能。 我非常喜欢底部导航栏的外观和图标等等,所以我决定选择这个选项。 我实现它的方式如下:我声明了一个静态常量列表元素=[…],其中我目前只有四个Text()小部件。我还声明了一个变量selectedIndex,以便跟踪应该显示的元素。然后,在我的Scaffold中,我将bottomNavigationBar设置为bottomNavigationBar(),其中有一个BottomNavigationBarItems的常量列表,我想其余的参数是显
静态常量列表元素=[…]
,其中我目前只有四个Text()
小部件。我还声明了一个变量selectedIndex
,以便跟踪应该显示的元素。然后,在我的Scaffold中,我将bottomNavigationBar设置为bottomNavigationBar()
,其中有一个BottomNavigationBarItems的常量列表,我想其余的参数是显而易见的。
当我将const添加回,但保持列的原样时,我得到以下结果:
Compiler message:
lib/main.dart:39:5: Error: Cannot invoke a non-'const' constructor where a const expression
is expected.
Try using a constructor or factory that is 'const'.
Column(
^^^^^^
现在问题来了:
当我试图在我的元素列表中放置一列时,我会遇到一些不同的错误:
Const variables must be initialized with a constant value.
The constructor being called isn't a const constructor
但我真的需要两个小部件,一个在另一个之上,我的应用程序才能正常工作。
有人知道我到底是怎么做到的吗
我尝试过的:
我尝试将该列作为一个单独的变量,但没有成功,并给了我相同的错误。
当我从elements
列表中删除const
以便添加列时,它没有抛出错误,也没有显示我在列中输入的两个内容
我的代码(至少相关位):
class\u MyStatefulWidgetState扩展状态{
int _geselecteerdeIndex=0;
静态常量TextStyle tekstStijl=TextStyle(fontSize:30,fontWeight:fontWeight.bold);
静态常量列表元素=[
正文(
“索引0:地图”,
款式:tekstStijl,
),
正文(
“索引1:历史”,
款式:tekstStijl
),
正文(
“指数2:挑战”,
款式:tekstStijl,
),
正文(
“索引3:设置”,
款式:tekstStijl
),
];
void\u未映射(整数索引){
设置状态(){
_geselecteerdeIndex=指数;
});
}
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:const Text('INTERSHITY v.0.1.0'),
背景颜色:颜色。琥珀色[300],
),
正文:中(
子元素:elementen.elementAt(_geselecteerdeIndex),
),
底部导航栏:底部导航栏(
项目:常数[
底部导航气压计(
图标:图标(Icons.map),
标题:文本(“地图”)
),
底部导航气压计(
图标:图标(图标。趋势向上),
标题:文本(“历史”)
),
底部导航气压计(
图标:图标(Icons.casino),
标题:文本(“挑战”)
),
底部导航气压计(
图标:图标(图标.设置),
标题:文本(“设置”)
)
],
当前索引:\u geselecteerdeIndex,
selectedItemColor:Colors.amber[800],
onTap:\u未映射,
背景颜色:颜色。灰色[300],
类型:BottomNavigationBarType.fixed,
显示未选择的标签:false,
),
);
}
}
我的详细信息:
- OS:Ubuntu 18.04 64位
- 颤振版本:1.9.1
- 我用于测试的设备:只是针对x86的Android仿真器
列
没有常量
构造函数,因此不能将常量
与列
一起使用(这些错误基本上就是这么说的)
这应该起作用:
final List<Widget> elementen = <Widget>[
Column(
children: <Widget>[
Text(
"Index 0: Map",
style: tekstStijl,
),
FlutterLogo(),
],
),
Column(
children: <Widget>[
Text("Index 1: History", style: tekstStijl),
FlutterLogo(),
],
),
Column(
children: <Widget>[
Text(
"Index 2: Challenges",
style: tekstStijl,
),
FlutterLogo(),
],
),
Column(
children: <Widget>[
Text("Index 3: Settings", style: tekstStijl),
FlutterLogo(),
],
),
];
final List elementen=[
纵队(
儿童:[
正文(
“索引0:地图”,
款式:tekstStijl,
),
徽标(),
],
),
纵队(
儿童:[
文本(“索引1:历史”,样式:tekstStijl),
徽标(),
],
),
纵队(
儿童:[
正文(
“指数2:挑战”,
款式:tekstStijl,
),
徽标(),
],
),
纵队(
儿童:[
文本(“索引3:设置”,样式:tekstStijl),
徽标(),
],
),
];
天哪,我怎么会这么瞎?多谢各位
final List<Widget> elementen = <Widget>[
Column(
children: <Widget>[
Text(
"Index 0: Map",
style: tekstStijl,
),
FlutterLogo(),
],
),
Column(
children: <Widget>[
Text("Index 1: History", style: tekstStijl),
FlutterLogo(),
],
),
Column(
children: <Widget>[
Text(
"Index 2: Challenges",
style: tekstStijl,
),
FlutterLogo(),
],
),
Column(
children: <Widget>[
Text("Index 3: Settings", style: tekstStijl),
FlutterLogo(),
],
),
];