当用户点击 中的项目时CupertinoTabView
,我想每次都重新加载页面。现在,它只是第一次加载。下一次它只显示以前的状态。我想强制重新加载它。例如,当用户点击 pageThree 时,即下面代码中 switch case 中的“case 2”,我想重新加载该页面。
这是我的代码:
class HomeScreen extends StatelessWidget {
int currentIndex = 0;
final GlobalKey<NavigatorState> pageOneTabNavKey = GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> pageTwoTabNavKey = GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> pageThreeTabNavKey = GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> pageFourTabNavKey = GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> pageFiveTabNavKey = GlobalKey<NavigatorState>();
@override
Widget build(BuildContext context) {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
activeColor: AppColor.pumpkinOrange,
inactiveColor: Colors.white,
backgroundColor: AppColor.peacockBlue,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home)
),
BottomNavigationBarItem(
icon: Icon(Icons.notifications_none),
),
BottomNavigationBarItem(
icon: Icon(Icons.star_border),
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
),
BottomNavigationBarItem(
icon: Icon(Icons.help_outline),
)
],
onTap: (index) {
switch (index) {
case 0:
pageOneTabNavKey.currentState.popUntil((r) => r.isFirst);
break;
case 1:
pageTwoTabNavKey.currentState.popUntil((r) => r.isFirst);
break;
case 2:
pageThreeTabNavKey.currentState.popUntil((r) => r.isFirst);
break;
case 3:
pageFourTabNavKey.currentState.popUntil((r) => r.isFirst);
break;
case 4:
pageFiveTabNavKey.currentState.popUntil((r) => r.isFirst);
break;
}
currentIndex = index;
},
),
tabBuilder: (BuildContext context, int index) {
return CupertinoTabView(builder: (BuildContext context) {
switch (index) {
case 0:
return CupertinoTabView(
navigatorKey: summaryTabNavKey,
builder: (BuildContext context) {
return MultiBlocProvider(
providers: <BlocProvider>[
BlocProvider<PageOneBloc>(
create: (BuildContext context) =>
PageOneBloc(FetchDataRepository())..add(LoadingEvent())
),
BlocProvider<DataBloc>(
create: (BuildContext context) => DataBloc()
)
],
child: PageOne(),
);
},
);
break;
case 1:
return CupertinoTabView(
navigatorKey: pageTwoTabNavKey,
builder: (BuildContext context) {
return MultiBlocProvider(
providers: <BlocProvider>[
BlocProvider<PageTwoBloc>(
create: (BuildContext context) =>
PageTwoBloc(PageTwoManager())
..add(LoadPageTwoEvent()),
),
BlocProvider<ScrolleventnotifierBloc>(
create: (BuildContext context) =>
ScrolleventnotifierBloc(),
),
],
child: PageTwo(),
);
},
);
break;
case 2:
return CupertinoTabView(
navigatorKey: pageThreeTabNavKey,
builder: (BuildContext context) {
return BlocProvider<PageThreeBloc>(
create: (BuildContext context) =>
PageThreeBloc()..add(UserReachesPageThreeEvent(noOfItems:5,pageNumber: 1)),
child: PageThree(),
);
},
);
break;
case 3:
return CupertinoTabView(
navigatorKey: pageFourTabNavKey,
builder: (BuildContext context) {
return BlocProvider<ProfileBloc>(
create: (BuildContext context) =>
ProfileBloc()..add(UserReachesProfilePageEvent()),
child: ProfilePage(),
);
},
);
break;
case 4:
return CupertinoTabView(
navigatorKey: helpTabNavKey,
builder: (BuildContext context) {
return BlocProvider<HelpBloc>(
create: (BuildContext context) =>
HelpBloc(FetchHelpRepository())..add(HelpLoadEvent()),
child: HelpPage(),
);
},
);
break;
}
return Container();
});
});
}
}