gpt4 book ai didi

flutter : CupertinoTabScaffold - Back button close app on Android from TabView's navigation

转载 作者:行者123 更新时间:2023-12-03 19:11:08 28 4
gpt4 key购买 nike

我有一个使用 CupertinoApp-CupertinoTabScaffold 的应用程序。

我的应用程序的层次结构

CupertinoApp
- CupertinoTabScaffold
-- CupertinoTabView
--- Home
---- Movie list
----- Movie Detail
--- Search
---- Movie Search List
----- Movie Detail
--- Profile
--- Settings

我刚刚在 Android 上意识到,即使在“电影详细信息”(从任何选项卡)中单击后退按钮应用程序也会关闭。

返回按钮应该真的从电影细节返回。

我搜索了 5 天,但找不到任何解决方案或解决此问题的方法。

此致,

乌特库Y。

最佳答案

我已经遇到这个问题很长时间了,经过大量搜索我找到了这个完美的解决方案: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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com