flutterlifecyclehooks 5.0.0 copy "flutterlifecyclehooks: ^5.0.0" to clipboard
flutterlifecyclehooks: ^5.0.0 copied to clipboard

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

example/lib/main.dart

import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutterlifecyclehooks/flutterlifecyclehooks.dart';

void main() {
  runApp(const App());
}

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  AppState createState() => AppState();
}

class AppState extends State<App> with LifecycleMixin {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SizedBox.expand(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                currentLifecycleState.toString(),
              ),
              const SimpleWidget(),
            ],
          ),
        ),
      ),
    );
  }

  @override
  void onAppLifecycleChange(AppLifecycleState state) {
    setState(() {});
  }

  @override
  void onAppShow() {
    debugPrint('did show');
  }

  @override
  void onAppHide() {
    debugPrint('did hide');
  }

  @override
  void onAppResume() {
    debugPrint('did resume');
  }

  @override
  void onAppPause() {
    debugPrint('did pause');
  }

  @override
  void onAppInactive() {
    debugPrint('app inactive');
  }

  @override
  void onAppRestart() {
    debugPrint('app restarted');
  }

  @override
  void onAppDetach() {
    debugPrint('app detached');
  }

  @override
  Future<AppExitResponse> onExitAppRequest() {
    debugPrint('on app exit request');
    return super.onExitAppRequest();
  }
}

class SimpleWidget extends StatelessWidget {
  const SimpleWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return LifecycleHooksSubscriber(
      onAppResume: () =>
          debugPrint('onAppResume from SimpleWidget LifecycleHooksSubscriber'),
      child: const Text('SimpleWidget'),
    );
  }
}
52
likes
160
points
2.03k
downloads

Publisher

verified publisherptsakoulis.com

Weekly Downloads

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutterlifecyclehooks