flutterlifecyclehooks 1.0.1

Flutter Android iOS web

A flutter package that let you easily add hooks for application lifecycle state

flutterlifecyclehooks #

A flutter package that lets you easily add hooks for application lifecycle state LifecycleMixin just implements the WidgetsBindingObserver and invokes the callbacks onResume, onPause, onDetached, afterFirstRender, for you. You can use the other callbacks provided by WidgetsBindingObserver https://api.flutter.dev/flutter/widgets/WidgetsBindingObserver-class.html You don't need to manually call onDispose to deregister.

Getting Started #

Add on pubspec.yaml

dependencies:
    flutterlifecyclehooks: version

Example code #

class App extends StatefulWidget {
  @override
  _AppState createState() => _AppState();
}  

class _AppState extends State<App> with LifecycleMixin {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text(
            currentLifecycleState.toString(),
          ),
        ),
      ),
    );
  }

  @override
  void onPause() {
    print('did pause');
  }

  @override
  void onResume() {
    print('did resume');
  }
  
  /// optionally
  @override
  void afterFirstRender() {
    print('run after first render');
  }
}
9
likes
110
pub points
74%
popularity

A flutter package that let you easily add hooks for application lifecycle state

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

spideythewebhead@gmail.com

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutterlifecyclehooks