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

Add an (optional) way to make a ViewModel life cycle aware (foreground / background) #1

Open
gcx-service-bot opened this issue Sep 4, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@gcx-service-bot
Copy link

  • the ViewModel should have an empty method which can receive those notifications
  • we need a mixin that can be used by State which automatically wires a WidgetBindingObserver to the viewModel

maybe s.th. like this (not tested)

mixin LifecycleAwareState<T extends StatefulWidget> on State<T>  implements WidgetsBindingObserver {
  ViewModel get _viewModel;
  @override
  @mustCallSuper
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }
  @override
  @mustCallSuper
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    // TODO: implement
  }
}

Currently unclear if this is possible (this way) with Dart

Original by @bquentin

@gcx-service-bot gcx-service-bot added the enhancement New feature or request label Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant