mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 16:14:49 +01:00
fix: back button android, return home on tap (#59)
* fix: back button android, return home on tap * fix: reuse logic for platforms
This commit is contained in:
parent
805f065def
commit
98f102faec
@ -26,6 +26,16 @@ class Home extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HomeState extends State<Home> {
|
class _HomeState extends State<Home> {
|
||||||
|
|
||||||
|
// Created 5 different variables instead of a list as list doesn't work
|
||||||
|
final GlobalKey<NavigatorState> tab1 = GlobalKey<NavigatorState>();
|
||||||
|
final GlobalKey<NavigatorState> tab2 = GlobalKey<NavigatorState>();
|
||||||
|
final GlobalKey<NavigatorState> tab3 = GlobalKey<NavigatorState>();
|
||||||
|
final GlobalKey<NavigatorState> tab4 = GlobalKey<NavigatorState>();
|
||||||
|
final GlobalKey<NavigatorState> tab5 = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
|
final List<Widget> screens = List<Widget>();
|
||||||
|
|
||||||
int active = 0;
|
int active = 0;
|
||||||
|
|
||||||
_buildScreen(int index) {
|
_buildScreen(int index) {
|
||||||
@ -174,23 +184,56 @@ class _HomeState extends State<Home> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GlobalKey<NavigatorState> getNavigatorKey(int index) {
|
||||||
|
switch(index) {
|
||||||
|
case 0:
|
||||||
|
return tab1;
|
||||||
|
case 1:
|
||||||
|
return tab2;
|
||||||
|
case 2:
|
||||||
|
return tab3;
|
||||||
|
case 3:
|
||||||
|
return tab4;
|
||||||
|
case 4:
|
||||||
|
return tab5;
|
||||||
|
}
|
||||||
|
return tab1;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Provider.of<ThemeModel>(context);
|
final theme = Provider.of<ThemeModel>(context);
|
||||||
final auth = Provider.of<AuthModel>(context);
|
final auth = Provider.of<AuthModel>(context);
|
||||||
|
final CupertinoTabController _controller = CupertinoTabController();
|
||||||
if (auth.activeAccount == null) {
|
if (auth.activeAccount == null) {
|
||||||
return LoginScreen();
|
return LoginScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (theme.theme) {
|
switch (theme.theme) {
|
||||||
case AppThemeType.cupertino:
|
case AppThemeType.cupertino:
|
||||||
return CupertinoTabScaffold(
|
return WillPopScope(
|
||||||
tabBar: CupertinoTabBar(items: _navigationItems),
|
onWillPop: () async {
|
||||||
tabBuilder: (context, index) {
|
return !await getNavigatorKey(_controller.index).currentState.maybePop();
|
||||||
return CupertinoTabView(builder: (context) {
|
|
||||||
return _buildScreen(index);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
child: CupertinoTabScaffold(
|
||||||
|
controller: _controller,
|
||||||
|
tabBuilder: (context, index) {
|
||||||
|
return CupertinoTabView(
|
||||||
|
navigatorKey: getNavigatorKey(index),
|
||||||
|
builder: (context) {
|
||||||
|
return _buildScreen(index);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
tabBar: CupertinoTabBar(items: _navigationItems,
|
||||||
|
onTap: (index) {
|
||||||
|
if(active == index) {
|
||||||
|
getNavigatorKey(index).currentState.popUntil((route) => route.isFirst);
|
||||||
|
}
|
||||||
|
active = index;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user