You can monitor page lifecycle by this lib.

Overview

lifecycle_lite

通过简单几步,就可以让你使用whenShow()/whenHide()方法来监听页面的生命周期(退回到了该页面/打开其他页面挡着了该页面)了

Principle

这个库的实现很简单,你完全可以通过阅读代码后自己扩展实现。主要就是在MaterialApp中添加一个对路由的监听,也就是MaterialApp#navigatorObservers,之后通过对路由的监听来记录一个路由的栈。再在对应的State#initState方法或StatelessWidget#createElement中绑定两个生命周期方法的实现到最上层路由。 这样在每次监听到路由变化时,去调用顶层路由对应的绑定方法就OK了。 记得在路由被移出的时候对应的方法也要移出哦~

  • StatefulWidget
  • StatelessWidget

Getting Started

lifecycle_lite: ^0.0.3

1.首先在你的根布局MaterialApp中绑定一个路由监听LifeNavigatorObserver().

    MaterialApp(
        navigatorObservers: [
            LifeNavigatorObserver(),
        ],
    );

2.在你需要添加监听的State中混入LifecycleMixin,并在initState中调用bindImplIntoRoute()方法。

2.StatefulWidget的话,需要混入LifecycleStatefulMixin,对应的StatelessWidget,使用的是LifecycleStatelessMixin

3.实现whenShow()/whenHide()方法,代码看起来是下面的样子。

///Statefule page
class WorksDetailState extends State with LifecycleStatefulMixin{

    @override
    whenShow() {
        super.whenShow();
        print("LifeNavigatorObserver---Show了");
    }

    @override
    whenHide() {
        super.whenHide();
        print("LifeNavigatorObserver---Hide了");
    }
}
///Stateless page
class StatelessPage extends StatelessWidget with LifecycleStatelessMixin{

    @override
    whenShow() {
        super.whenShow();
        print("LifeNavigatorObserver---Show了");
    }

    @override
    whenHide() {
        super.whenHide();
        print("LifeNavigatorObserver---Hide了");
    }
}

尽情享用吧 :P;

You might also like...

WAS-Monitor für die Feuerwehren in Oberösterreich

WAS-Monitor für die Feuerwehren in Oberösterreich

FF WAS-Monitor Oberösterreich Demo Unterstützte Betriebssysteme Der WAS-Monitor unterstützt die neuesten, stabilen Versionen von Linux und Windows. Do

Oct 31, 2021

Plant-monitor - Plant monitoring system using IoT, MongoDB, and Flutter

Plant Monitor IoT based plant monitoring system which is connected to MongoDB. T

Dec 1, 2022

Para-managment: The app is to monitor and manage your personal finance

Para-managment: The app is to monitor and manage your personal finance

Pare | پارە Pare App Demo The app is to monitor and manage your personal finance You have a category for each category you have category name, icon, a

Mar 20, 2022

Page Turn Widget - Add a page turn effect to widgets in your app. Maintainer: @rodydavis

Page Turn Widget - Add a page turn effect to widgets in your app. Maintainer: @rodydavis

Page Turn Widget Add a page turn effect to widgets in your app. Created by Simon Lightfoot @slightfoot Screenshots Example import 'package:flutter/mat

Dec 29, 2022

A mobile image uploader in which you can upload image to your personal gallery from either your camera or mobile gallery and it can detect your current geographic location and address using firebase firestore and storage.

Image Uploader In Flutter About It is an Image Uploader gallery which tracks your address from which you're uploading using Flutter and Image picker.

Dec 20, 2022

A flutter app for a wordpress websites with clean and elegant design. This app is available in free and pro version. You can choose to use the one you need.

A flutter app for a wordpress websites with clean and elegant design. This app is available in free and pro version. You can choose to use the one you need.

📌 Get Flutter for Wordpress Flutter for wordpress is currently available in free and pro version: Flutter for Wordpress Flutter for Wordpress Pro Bea

Dec 13, 2022

A flutter app face detection and emotion, can detect if you're smiling, big smiley, sad or if there is not face on the screen.

My Emotion A flutter app face detection and emotion, can detect if you're smiling, big smiley, sad or if there is not face on the screen. News feactur

Dec 31, 2022

Real short video app with firebase and pixels API.Where you can create a short video with pixels' stock videos and also merge your audio.

Real short video app with firebase and pixels API.Where you can create a short video with pixels' stock videos and also merge your audio.

Flutter Short Videos Platform Short videos platform with Flutter and Firebase. About Real short video app with firebase and pixels API.Where you can c

Dec 26, 2022
Owner
Lpoint
Lpoint
A web dashboard that allows you to monitor your Chia farm and sends notifications when blocks are found and new plots are completed through a discord bot. It can link multiple farmers/harvesters to your account.

farmr A web dashboard that allows you to monitor your Chia farm and sends notifications when blocks are found and new plots are completed through a di

Gil Nobrega 261 Jan 2, 2023
Flutter Print Lib

Some documents are not translated into English, welcome to submit RP RarePrint This is a rendering library for printing. Support preview, use p

null 13 Oct 21, 2022
About This is Personal Expenses Planner. You can add your expenses in to the app and manage your transaction. and you can see How much did you spend on which day. I developed this project using flutter.

expense_planner A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Darshit Rudani 5 Jul 6, 2022
A Simple Todo app design in Flutter to keep track of your task on daily basis. Its build on BLoC Pattern. You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates

WhatTodo Life can feel overwhelming. But it doesn’t have to. A Simple To-do app design in flutter to keep track of your task on daily basis. You can a

Burhanuddin Rashid 1k Jan 6, 2023
This is a shop-app you can see the products and With prices and knowing if there are discounts and adding your favorite products to the favorite products page

This is a shop-app you can see the products and With prices and knowing if there are discounts and adding your favorite products to the favorite products page, you can search for a specific product and also modify personal information from the settings , I made it using REST APIs by using (Dio packedge) , (shared Preference) and state management (Bloc/cubit

null 2 Oct 27, 2022
Workshop Flutter กับ มาสเตอร์ อึ่ง ทำแอพ Monitor Covid

คอร์ส สอน Flutter ตัวต่อต่อ เลือก หัวข้อเรียนได้ Workshop With มาสเตอร์ อึ่ง ต้องการรายละเอียดเพิ่ม หรือ ต้องการ ปรึกษาการทำ โปรเจคแอนดรอยด์ ติดต่อมาส

มาสเตอร์ อึ่ง 3 Feb 7, 2022
Health Performance Monitor ui design in a neomorphism style.

Health Performance Monitor UI Health Performance Monitor ui design in a neomorphism effect built using Flutter. Show some ❤️ and star the repo, it mak

Roshini Mahendran 11 Jun 17, 2022
This is a smart farming app which helps farmers to remotely monitor their crop and take necessary actions. It also has a feature called disease detection.

Smart-Farming-App This is a smart farming app which helps farmers to remotely monitor their crop and take necessary actions. It has features called di

Nihar Shah 2 Jul 9, 2022
The ultimate baby monitor! This mobile app helps new parents keep track of all their newborn baby's needs, milestones, and reminders in one place!

New Parent The ultimate baby monitor! This mobile app helps new parents keep track of all their newborn baby's needs, milestones, and reminders in one

ACM Projects 6 Jun 22, 2022
Android app created to monitor location, gyroscope readings, pedometer measurements, and acceleration in different directions.

Blue Locator A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Mac Maxwell 3 Apr 6, 2022