page_life_cycle 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

page_life_cycle #

由于flutter本身widget没有路由onShow,onHide事件,根据路由变化增加widget的onShow,onHide事件,同时继承了WidgetsBindingObserver的didChangeAppLifecycleState app周期,同时优化了app进入前后台事件 只触发当前路由是顶层路由的widget,而不是所有的路由

Getting Started #

首次使用 #

   main.dart

   import 'package:page_life_cycle/page_life_cycle.dart' show PageNavigatorObserver;


   MaterialApp(
       navigatorObservers: [PageNavigatorObserver()]
   )

Widget内使用 #

1.1.0版本 #

   main.dart

   import 'package:page_life_cycle/page_life_cycle.dart';



  class VideoWidgetState extends State<VideoWidget>
    with PageLifeCycle  {
    // 路由显示触发
    @override
    void onShow () {

    }
    
    // 路由隐藏触发
    @override
    void onHide () {

    }
    // app 进入后台,只触发当前路由内绑定的widget
    @override
    void onAppBackground () {

    }
    // app 进入前台,只触发当前路由内绑定的widget
    @override
    void onAppForeground () {

    }
    // 判断是否是顶层路由 会过滤没有name的route 和 modelPopupRoute 需要在addPageLifeCycleObserver方法后调用
    bool getIsTopRoute => PageLifeCycleObserver().getIsTopRoute(this)

   }
+

1.1.0之前版本 #

   main.dart

   import 'package:page_life_cycle/page_life_cycle.dart';

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 => PageLifeCycleObserver().getIsTopRoute(this)

   }

[1.1.1] - TODO: 2019-12-24.

  • TODO: fix onAppBackground.

[1.1.0] - TODO: Add release date.

  • TODO: Remove manual add listening.

[1.0.8] - TODO: Add release date.

  • TODO: support no route name.

[1.0.6] - TODO: Add release date.

  • TODO: Describe initial release.

[1.0.2] - fix readme.md.

  • fix readme.md.

[1.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

[1.0.0] - fix readme.md.

  • fix readme.md.

example/README.md

tencent_native_video_example #

Demonstrates how to use the tencent_native_video plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  page_life_cycle: ^1.1.1

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]
40
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/page_life_cycle.dart. (-1 points)

Analysis of lib/page_life_cycle.dart reported 2 hints:

line 12 col 28: The value of the field '_appLifecycleState' isn't used.

line 139 col 12: The value of the local variable 'name' isn't used.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test