底部努力栏,带有动态菜单中的动态菜单
我尝试以动态菜单为底部的navigatorbar,来自提供商。
它的“错误工作”。
以下断言是抛弃了FutureBuilder(Dirty, 状态:_FutureBuilderState#DBBBC): '软件包:flutter/src/材料/bottom_navigation_bar.dart':失败 断言:第186行POS 15:'items.length> = 2':不正确。
class ChartPageViewer extends StatefulWidget {
const ChartPageViewer({Key? key}) : super(key: key);
@override
_ChartPageViewerState createState() => _ChartPageViewerState();
}
class _ChartPageViewerState extends State<ChartPageViewer> {
double? yas;
double? boy;
String tablo = "neyzi";
PageController pageController = PageController(initialPage: 0);
int currentindex = 0;
@override
void initState() {
yas = context.read<HastaVeriKaydet>().yas?.toDouble();
boy = double.parse(context.read<HastaVeriKaydet>().boy!);
tablo = context.read<HastaVeriKaydet>().tablo!;
PersentilChartRepository().runServices(
yas: yas != null ? yas! : 0,
olcum: boy != null ? boy! : 0,
olcumtipi: 'boy',
cinsiyet: cinsiyet,
tablo: tablo);
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
Provider.of<PersentilChartRepository>(context, listen: false)
.addtabloListesi(
tablo: tablo, cinsiyet: cinsiyet, yas: yas.toString());
});
super.initState();
}
@override
Widget build(BuildContext context) {
List<String>? menuListesi =
Provider.of<PersentilChartRepository>(context).tabloListesi != null
? Provider.of<PersentilChartRepository>(context).tabloListesi
: null;
if (tablo == 'cdc' && yas! >= 36) {
menuListesi!.remove('bascevresi');
}
if (tablo == 'who' && yas! >= 120) {
menuListesi!.remove('kilo');
}
StatefulWidget menuEslestir(String menu) {
switch (menu) {
case 'boy':
return HeightChart();
case 'kilo':
return WeightChart();
case 'bascevresi':
return Bascevresi();
case 'bmi':
return Bmi();
case 'boyagorekilo':
return Boyagorekilo();
default:
return HeightChart();
}
}
List<BottomNavigationBarItem> barItem() {
return menuListesi!.map((e) {
Widget itemicon = Icon(Icons.star);
if (e == 'boy') {
itemicon = Icon(Icons.home);
} else if (e == 'kilo') {
itemicon = Icon(Icons.opacity);
} else if (e == 'bascevresi') {
itemicon = Icon(Icons.map);
} else if (e == 'bmi') {
itemicon = Icon(Icons.close);
} else if (e == 'boyagorekilo') {
itemicon = Icon(Icons.search);
}
return BottomNavigationBarItem(icon: itemicon, label: e);
}).toList();
}
return Scaffold(
bottomNavigationBar: FutureBuilder(
future: Future.delayed(Duration(milliseconds: 100), () {
// Do something
}),
builder: (context, snapshot) {
return BottomNavigationBar(
onTap: (index) {
pageController.animateToPage(index,
duration: Duration(milliseconds: 100), curve: Curves.linear);
},
backgroundColor: Colors.blueGrey,
selectedItemColor: Colors.black,
unselectedItemColor: Colors.grey,
currentIndex: currentindex,
items: barItem(),
);
},
),
body: PageView.builder(
itemCount: menuListesi!.length,
controller: pageController,
pageSnapping: true,
onPageChanged: (index) {
setState(() {
currentindex = index;
});
},
itemBuilder: (context, i) {
return menuEslestir(menuListesi[i]);
},
),
);
}
}
这是在屏幕上的工作,但是有错误运行屏幕。我不想有任何问题。
如果我将print(baritem()。lenght)放在navigatorbar bloc中,我可以在控制台中看到三倍的长度 第一个lenght值为0; 其他值是实数。
I try to bottomnavigatorbar with dynamic menu comes from Provider.
Its' work with error.
The following assertion was thrown building FutureBuilder(dirty,
state: _FutureBuilderState#dbbbc):
'package:flutter/src/material/bottom_navigation_bar.dart': Failed
assertion: line 186 pos 15: 'items.length >= 2': is not true.
class ChartPageViewer extends StatefulWidget {
const ChartPageViewer({Key? key}) : super(key: key);
@override
_ChartPageViewerState createState() => _ChartPageViewerState();
}
class _ChartPageViewerState extends State<ChartPageViewer> {
double? yas;
double? boy;
String tablo = "neyzi";
PageController pageController = PageController(initialPage: 0);
int currentindex = 0;
@override
void initState() {
yas = context.read<HastaVeriKaydet>().yas?.toDouble();
boy = double.parse(context.read<HastaVeriKaydet>().boy!);
tablo = context.read<HastaVeriKaydet>().tablo!;
PersentilChartRepository().runServices(
yas: yas != null ? yas! : 0,
olcum: boy != null ? boy! : 0,
olcumtipi: 'boy',
cinsiyet: cinsiyet,
tablo: tablo);
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
Provider.of<PersentilChartRepository>(context, listen: false)
.addtabloListesi(
tablo: tablo, cinsiyet: cinsiyet, yas: yas.toString());
});
super.initState();
}
@override
Widget build(BuildContext context) {
List<String>? menuListesi =
Provider.of<PersentilChartRepository>(context).tabloListesi != null
? Provider.of<PersentilChartRepository>(context).tabloListesi
: null;
if (tablo == 'cdc' && yas! >= 36) {
menuListesi!.remove('bascevresi');
}
if (tablo == 'who' && yas! >= 120) {
menuListesi!.remove('kilo');
}
StatefulWidget menuEslestir(String menu) {
switch (menu) {
case 'boy':
return HeightChart();
case 'kilo':
return WeightChart();
case 'bascevresi':
return Bascevresi();
case 'bmi':
return Bmi();
case 'boyagorekilo':
return Boyagorekilo();
default:
return HeightChart();
}
}
List<BottomNavigationBarItem> barItem() {
return menuListesi!.map((e) {
Widget itemicon = Icon(Icons.star);
if (e == 'boy') {
itemicon = Icon(Icons.home);
} else if (e == 'kilo') {
itemicon = Icon(Icons.opacity);
} else if (e == 'bascevresi') {
itemicon = Icon(Icons.map);
} else if (e == 'bmi') {
itemicon = Icon(Icons.close);
} else if (e == 'boyagorekilo') {
itemicon = Icon(Icons.search);
}
return BottomNavigationBarItem(icon: itemicon, label: e);
}).toList();
}
return Scaffold(
bottomNavigationBar: FutureBuilder(
future: Future.delayed(Duration(milliseconds: 100), () {
// Do something
}),
builder: (context, snapshot) {
return BottomNavigationBar(
onTap: (index) {
pageController.animateToPage(index,
duration: Duration(milliseconds: 100), curve: Curves.linear);
},
backgroundColor: Colors.blueGrey,
selectedItemColor: Colors.black,
unselectedItemColor: Colors.grey,
currentIndex: currentindex,
items: barItem(),
);
},
),
body: PageView.builder(
itemCount: menuListesi!.length,
controller: pageController,
pageSnapping: true,
onPageChanged: (index) {
setState(() {
currentindex = index;
});
},
itemBuilder: (context, i) {
return menuEslestir(menuListesi[i]);
},
),
);
}
}
It's work on screen but there is error run screen. I don't want any problem.
If i put print(baritem().lenght) in navigatorbar bloc I can see three times length in console
First lenght value is 0 ;
other value is real number.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论