问题描述
我在项目底部导航,子项在indexedItems中。但是问题在于应用程序启动时会初始化其所有子项。就像iOS中的行为一样,它会初始化第一个孩子,而在选项卡上第一次点击时会初始化其他孩子。之后,它们将不会重新初始化。我如何实现相同的行为?
import '../../UI/logout/logoutScreen.dart';
import 'package:Flutter/material.dart';
import '../MyTask/MyTaskListScreen.dart';
import './../Home/HomeScreen.dart';
import 'package:hexcolor/hexcolor.dart';
class RootScreen extends StatefulWidget {
@override
_RootScreenState createState() => _RootScreenState();
}
class _RootScreenState extends State<RootScreen> {
final List<Widget> childScreens = [
HomeScreen(),MyTaskListScreen(),logoutScreen()
];
int _selectedindex = 0;
void _selectPage(int index,context) {
if (index == 2) {
logoutScreen().showlogoutView(context);
return;
}
this.setState(() {
this._selectedindex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: this._selectedindex,children: this.childScreens,),bottomNavigationBar: BottomNavigationBar(
onTap: (index) => this._selectPage(index,context),backgroundColor: Hexcolor("#f2f2f2"),unselectedItemColor: Colors.grey,selectedItemColor: Colors.blue,currentIndex: this._selectedindex,type: BottomNavigationBarType.fixed,showSelectedLabels: false,showUnselectedLabels: false,items: [
BottomNavigationBarItem(
activeIcon: ImageIcon(
Assetimage(
"lib/Source/Resources/Assets/Root/registration/active/activeRegistration.png"),color: Colors.black,icon: ImageIcon(
Assetimage(
"lib/Source/Resources/Assets/Root/registration/default/registration.png"),label: ""),BottomNavigationBarItem(
activeIcon: ImageIcon(
Assetimage(
"lib/Source/Resources/Assets/Root/myTask/active/myTask.png"),icon: ImageIcon(
Assetimage(
"lib/Source/Resources/Assets/Root/myTask/default/myTask.png"),BottomNavigationBarItem(
backgroundColor: Colors.lightBlue,icon: Icon(Icons.logout),label: "")
],));
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)