Skip to main content

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
points
40
downloads

Publisher

unverified uploader

Weekly Downloads

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

Packages that implement app_lifecycle