作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个使用 CupertinoApp-CupertinoTabScaffold 的应用程序。
我的应用程序的层次结构
CupertinoApp
- CupertinoTabScaffold
-- CupertinoTabView
--- Home
---- Movie list
----- Movie Detail
--- Search
---- Movie Search List
----- Movie Detail
--- Profile
--- Settings
最佳答案
我已经遇到这个问题很长时间了,经过大量搜索我找到了这个完美的解决方案:This solution is 100% accurate.我希望这有帮助。
我们正在寻求 Keys 的帮助,如果您不明白什么,请问我,我已经添加了代码。
///these are KEYS which are assigned to every Tab,
///the problem of navigation is solved by these KEYS
final GlobalKey<NavigatorState> firstTabNavKey = GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> secondTabNavKey = GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> thirdTabNavKey = GlobalKey<NavigatorState>();
CupertinoTabController tabController;
@override
void initState() {
// TODO: implement initState
super.initState();
tabController = CupertinoTabController(initialIndex: 0);
}
@override
Widget build(BuildContext context) {
//making a list of the keys
final listOfKeys = [firstTabNavKey, secondTabNavKey, thirdTabNavKey];
List homeScreenList = [
//list of different screens for different tabs
];
return CupertinoApp(
//this is important
home: WillPopScope(
onWillPop: () async {
return !await listOfKeys[tabController.index].currentState.maybePop();
},
child: CupertinoTabScaffold(
controller: tabController, //set tabController here
tabBar: CupertinoTabBar(
items: [
///this is where we are setting aur bottom ICONS
BottomNavigationBarItem(
label: 'AddClass',
icon: Icon(CupertinoIcons.add_circled_solid)),
BottomNavigationBarItem(
label: 'Profile', icon: Icon(CupertinoIcons.person_solid)),
BottomNavigationBarItem(
label: 'Joined', icon: Icon(CupertinoIcons.xmark_circle_fill)),
],
// currentIndex: pageIndex,
),
tabBuilder: (
context,
index,
) {
return CupertinoTabView(
navigatorKey: listOfKeys[
index], //set navigatorKey here which was initialized before
builder: (context) {
return homeScreenList[index];
},
);
},
),
),
);
}
关于 flutter : CupertinoTabScaffold - Back button close app on Android from TabView's navigation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62141565/
我正在使用下面的示例(取自 CupertinoTabScaffold documentation page )。 在选项卡内推送新路由时会出现“幻灯片”过渡,但是当我单击选项卡栏项目时,内容会被粗暴地
我有一个带有 LoginScreen 的应用程序,在成功登录后会转到 HomeScreen。我使用下面的代码替换小部件并启动新的导航堆栈: Navigator.pushReplacement(
我有一个使用 CupertinoApp-CupertinoTabScaffold 的应用程序。 我的应用程序的层次结构 CupertinoApp - CupertinoTabScaffold -- C
我是一名优秀的程序员,十分优秀!