page_life_cycle 1.0.4
page_life_cycle #
由于flutter本身widget没有路由onShow,onHide事件,根据路由变化增加widget的onShow,onHide事件,同时继承了WidgetsBindingObserver的didChangeAppLifecycleState app周期,同时优化了两点,1.只触发当前路由是顶层路由的widget,2.优化在ios上AppLifecycleState.paused延迟触发的表现
注意 #
本包只检测带有路由名称的路由,无名称的路由不会检测到, 推荐配合fluro 使用
Getting Started #
首次使用 #
main.dart
import 'package:page_life_cycle/page_life_cycle.dart' show PageNavigatorObserver;
MaterialApp(
navigatorObservers: [PageNavigatorObserver()]
)
页面内使用 #
one #
main.dart
import 'package:page_life_cycle/page_life_cycle.dart' show PageNavigatorObserver;
PageLifeCycleObserver lifeCycle = PageLifeCycleObserver();
class VideoWidgetState extends State<VideoWidget>
with PageLifeCycle {
@override
void didChangeDependencies() {
super.didChangeDependencies();
lifeCycle.addPageLifeCycleObserver(this, ModalRoute.of(context));
}
@override
void dispose() {
super.dispose();
lifeCycle.removePageLifeCycleObserver(this);
}
}
// 路由显示触发
@override
void onShow () {
}
// 路由隐藏触发
@override
void onHide () {
}
// app 进入后台,只触发当前路由内绑定的widget
@override
void onAppBackground () {
}
// app 进入前台,只触发当前路由内绑定的widget
@override
void onAppForeground () {
}
// 判断是否是顶层路由 会过滤没有name的route 和 modelPopupRoute 需要在addPageLifeCycleObserver方法后调用
bool getIsTopRoute => pageNavigatorObserver.getIsTopRoute(this)
}
[1.0.0] - fix readme.md.
- fix readme.md.
[0.0.2] - fix readme.md.
- fix readme.md.
[0.0.1] - TODO: Add release date.
- TODO: Describe initial release.
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
page_life_cycle: ^1.0.4
2. Install it
You can install packages from the command line:
with Flutter:
$ flutter pub get
Alternatively, your editor might support flutter pub get
.
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
import 'package:page_life_cycle/page_life_cycle.dart';
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
0
|
Health:
Code health derived from static analysis.
[more]
|
100
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
100
|
Overall:
Weighted score of the above.
[more]
|
50
|
Learn more about scoring.
We analyzed this package on Dec 4, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.6.1
- pana: 0.12.21
- Flutter: 1.9.1+hotfix.6
Platforms
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Dependencies
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.1.0 <3.0.0 | ||
flutter | 0.0.0 | ||
Transitive dependencies | |||
collection | 1.14.11 | 1.14.12 | |
meta | 1.1.7 | 1.1.8 | |
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test |