Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old state shown on previous pages on active inhibitor change #668

Closed
5 tasks done
tamslo opened this issue Oct 17, 2023 · 0 comments · Fixed by #679
Closed
5 tasks done

Old state shown on previous pages on active inhibitor change #668

tamslo opened this issue Oct 17, 2023 · 0 comments · Fixed by #679
Labels
P: App Project: App Study: Must have T: Fix Type: Bug Fixes

Comments

@tamslo
Copy link
Collaborator

tamslo commented Oct 17, 2023

Desired behavior: for the gene report and drug search tab, data should update in the respective inactive tab after an active medication change (optimally; always also possible)

Currently implementing: solution using ChangeNotifier

  • Add provider and change notifier for active medications
  • Use consumers everywhere where UserData.instance.activeDrugNames is used to manipulate activeMedications
  • Use consumers everywhere where UserData.instance.activeDrugNames is used in the UI
  • Test in simulator
  • Adapt/write tests

Possible solutions

  • Add maintainState: false toAutoRoute definitions in lib/report/module.dart and lib/search/module.dart (see StackOverflow)
    • Only in empty root route: updates state but always goes back to main route, which is not really the desired behavior, but might work if no other solution does
    • Only in child routes: does not change behavior on tab change; introduces bug that drug list is filtered by name but name is not present anymore (it does not go back to the full list), additionally throws unhandled exceptions
    • In all routes: combination of cases above
  • Manipulate router stack in lib/common/pages/drug/widgets/annotation_cards/drug.dart (inside CupertinoDialogAction:onPressed)
    • Navigator.popUntil(context, (route) => false);: Removes everything from the router (including tabs) and throws unhandled exceptions
    • Get current tab router and navigate to index (see below), while adding maintainState: false to root child routes (see above): works perfectly for report page reset but not drugs page, probably due to filter state; also not optimal from usability perspective, would be better if data just updates
    • Refactor routes to only get minimum information (e.g., drug name or gene name) and always fetch further information dynamically (need to test whether re-build is triggered then): _not tried yet, probably need to use maintainState and will have same problems as above
    • Use change notifier (see example): trying out...

Code that does not work but might be useful in the future: get dependent tab and navigate to root:

class TabInfo {
  TabInfo({
    required this.label,
    required this.index,
  });
  String label;
  int index;
}

TabRouteDefinition getTabToReset(BuildContext context) {
  final interdependentRouteTypes = [ ReportRouter, SearchRouter ];
  final tabsRouter = context.router.childControllers[0] as TabsRouter;
  final tabRouteDefintion = getTabRoutesDefinition(context);
  final activeRouteType =
    tabRouteDefintion[tabsRouter.activeIndex].pageRouteInfo.runtimeType;
  final routeTypeToReset = interdependentRouteTypes.filter(
    (route) => route != activeRouteType
  ).first;
  return tabRouteDefintion.filter(
    (routeDefinition) =>
      routeDefinition.pageRouteInfo.runtimeType == routeTypeToReset
  ).first;
}

String getTabLabelToReset(BuildContext context) {
  return getTabToReset(context).label;
}

void resetDependentTab(BuildContext context) {
  final tabsRouter = context.router.childControllers[0] as TabsRouter;
  final tabRoutesDefintion = getTabRoutesDefinition(context);
  final dependentTab = getTabToReset(context);
  final dependentTabIndex = tabRoutesDefintion.indexWhere(
    (routeDefinition) => routeDefinition.label == dependentTab.label  
  );
  tabsRouter.stackRouterOfIndex(dependentTabIndex)?.popUntilRoot();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P: App Project: App Study: Must have T: Fix Type: Bug Fixes
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant