Search packages, repositories and app categories

Package detailsv5.0.0

flutterlifecyclehooks

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

AndroidiOSWebmacOSWindowsLinux
30-day downloads
958
Likes
52
Pub points
150

Install package

flutter pub add flutterlifecyclehooks

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

FlutterLifecycleHooks is a lightweight package that enables developers to easily attach custom logic to key application lifecycle events in Flutter apps. It provides hooks for states such as app startup, backgrounding, and termination across all supported platforms—including mobile, web, and desktop. By integrating these hooks, developers can manage resources, save state, or trigger actions at precise moments during the app's lifecycle. The package simplifies lifecycle management without requiring boilerplate code or complex state handling.

Use cases

  • Managing app state on resume
  • Cleaning up resources when app goes to background
  • Saving user data before app terminates
  • Handling push notifications on app launch
  • Optimizing performance during lifecycle transitions

Key features

  • Simple hook-based API
  • Cross-platform support
  • Minimal boilerplate
  • Supports all Flutter platforms
  • Easy integration with existing code

Suitable for

  • Developers managing app lifecycle events
  • Apps needing precise control over startup/shutdown
  • Projects using functional programming patterns
  • Teams wanting clean lifecycle management
  • Apps with background processing needs

Considerations

  • Requires understanding of Flutter lifecycle
  • May increase complexity if overused
  • Not suitable for simple apps with no lifecycle logic
  • Limited to lifecycle-specific tasks
  • Does not replace full state management solutions

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

flutterlifecyclehooks

A flutter package that lets you easily add hooks for application lifecycle state. LifecycleMixin uses the AppLifecycleListener and registers methods as hooks.

The list of hooks is:

  • onAppShow
  • onAppHide
  • onAppRestart
  • onAppResume
  • onAppPause
  • onAppInactive
  • onAppDetach
  • onExitAppRequest

Note: Read more about these lifecycle hooks https://api.flutter.dev/flutter/widgets/AppLifecycleListener-class.html

Optionally provides onContextReady that acts like initState but BuildContext is available for use.

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 onAppLifecycleChange(AppLifecycleState state) {
    setState(() {});
  }

  @override
  void onResume() {
    print('did resume');
  }

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

Also you can use, LifecycleHooksSubscriber wraps a widget and provides convient arguments for lifecycle hooks.

You can use this if you don't want to polute the namespace of a stateful widget.

Categories

Source repository

Projects using this package

No data available yet.