app_lifecycle 0.0.1 copy "app_lifecycle: ^0.0.1" to clipboard
app_lifecycle: ^0.0.1 copied to clipboard

Native lifecycle functions that support iOS and Android, unlike WidgetBindings that comes with flutter.

example/lib/main.dart

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> eventStrings = ['first null'];

  @override
  void initState() {
    super.initState();
    AppLifecycle.lifeCycleStream.listen((event) {
      print('event = $event');
      eventStrings.add("${DateTime.now()} --- ${event.shortStr}");
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: ListView.separated(
            itemCount: eventStrings.length,
            separatorBuilder: (context, index) => Container(
              height: 0.3,
              color: Colors.grey,
            ),
            itemBuilder: (context, index) {
              return Container(
                height: 30,
                child: Center(child: Text('${eventStrings[index]}')),
              );
            },
          ),
        ),
      ),
    );
  }
}
1
likes
20
pub points
53%
popularity

Publisher

unverified uploader

Native lifecycle functions that support iOS and Android, unlike WidgetBindings that comes with flutter.

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on app_lifecycle