Skip to content

Commit

Permalink
🐛 Add an GlobalKey to KAGAppState
Browse files Browse the repository at this point in the history
Through some change (probably in flutter itself) there
is a problem where the TabBarView does not update itself.
Adding a GlobalKey to the Scaffold seems to change this.
  • Loading branch information
strifel committed Apr 2, 2022
1 parent bce379b commit e2ad30b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,16 @@ enum AppType {
}

class KAGAppState extends State<KAGApp> with TickerProviderStateMixin {
AppType type = getDefaultAppType();
AppType _type = getDefaultAppType();
GlobalKey _key = GlobalKey();
static KAGAppState app;
TabController controller;


@override
void initState() {
super.initState();
controller = TabController(initialIndex: 0, length: getPageCount(type), vsync: this); // If you change something here change it in build, too.
controller = TabController(initialIndex: 0, length: getPageCount(_type), vsync: this); // If you change something here change it in build, too.
API.of(context).hasLoginCredentials().then((loggedIn) => {
if (loggedIn) {
setState(() => type = getLoggedInAppType(webmail: API.of(context).requests.getUserInfo().mailConsent))
Expand All @@ -120,11 +121,12 @@ class KAGAppState extends State<KAGApp> with TickerProviderStateMixin {

@override
Widget build(BuildContext context) {
if (getPageCount(type) != controller.length) {
if (getPageCount(_type) != controller.length) {
controller = TabController(initialIndex: controller.index, length: getPageCount(type), vsync: this);
}
if (MediaQuery.of(context).size.width > 700 || (!kIsWeb && Platform.isMacOS)) { // !kIsWeb is required to not cause an exception by calling Platform on web.
return Row(
key: _key,
children: [
NavigationRail(
selectedIndex: controller.index,
Expand All @@ -141,26 +143,27 @@ class KAGAppState extends State<KAGApp> with TickerProviderStateMixin {
});
},
labelType: NavigationRailLabelType.selected,
destinations: getNavigationRail(type),
destinations: getNavigationRail(_type),
),
VerticalDivider(thickness: 2, width: 2, color: Theme.of(context).colorScheme.secondary),
// This is the main content.
Expanded(
child: IndexedStack(
index: controller.index,
children: AppViews(type),
children: AppViews(_type),
),
),
],
);
} else {
return Scaffold(
key: _key,
body: TabBarView(
controller: controller,
children: AppViews(type),
children: AppViews(_type),
physics: NeverScrollableScrollPhysics(),
),
bottomNavigationBar: BottomNavigationBarMenu(type, controller)
bottomNavigationBar: BottomNavigationBarMenu(_type, controller)
);
}
}
Expand Down Expand Up @@ -198,4 +201,11 @@ class KAGAppState extends State<KAGApp> with TickerProviderStateMixin {
}
return webmail ? AppType.NORMAL_WITH_WEBMAIL : AppType.NORMAL;
}

AppType get type => _type;

set type (AppType type) {
_type = type;
_key = GlobalKey();
}
}

0 comments on commit e2ad30b

Please sign in to comment.