v5.0.0
flutterlifecyclehooks
一個 Flutter 套件,讓您輕鬆為應用程式生命週期狀態新增鉤子
52喜歡 894近 30 天下載150Pub 分數
AndroidiOSWebmacOSWindowsLinux
spideythewebhead/flutterlifecyclehooks open-source repository details.
{"sdk":"flutter"}{"sdk":"flutter"}^5.4.2^2.0.1以下為英文專案原文快照,最新內容請造訪 GitHub。
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:
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.
Add on pubspec.yaml
dependencies:
flutterlifecyclehooks: version
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.