simple_lifecycle 0.0.4
simple_lifecycle: ^0.0.4 copied to clipboard
The simple_lifecycle package provides a simple and intuitive way to manage the state of your Flutter application. It allows you to categorize the app's lifecycle events into two distinct state, active [...]
import 'package:flutter/material.dart';
import 'package:simple_lifecycle/simple_lifecycle.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: ExampleScreen(),
);
}
}
class ExampleScreen extends StatefulWidget {
@override
_ExampleScreenState createState() => _ExampleScreenState();
}
class _ExampleScreenState extends State<ExampleScreen> {
SimpleLifecycle _lifecycle = SimpleLifecycle();
@override
void initState() {
super.initState();
_lifecycle.initialize();
_lifecycle.onAppActive = () {
print("App is active");
};
_lifecycle.onAppPaused = () {
print("App has been paused");
};
}
@override
void dispose() {
_lifecycle.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Example'),
),
body: Center(
child: Text('Example Screen'),
),
);
}
}