In the mobile application I developed with Flutter, I go to different screens from the home page. Then, when I go back to the home page, I need to dispose some providers.
In the project, I am using a customized AppScaffold to match the theme and these providers are called in this custom scaffold. So even if I navigate to other pages, there is always an AppScaffold at the bottom of the stack and the providers are not disposed. I found a solution for manual dispose as below, but I wonder if there is a better approach?
PopScope( onPopInvokedWithResult: (didPop, result) { final targetLocation = GoRouter.of(context).routerDelegate.state.name; if (targetLocation == AppRoutePaths.home) { ref.invalidate(dynamicMenuProvider); ref.invalidate(customerDebtStatusProvider); } }, child: Scaffold(), }