flutter_plugin_android_lifecycle 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

Flutter Android Lifecycle Plugin #

pub package

A Flutter plugin for Android to allow other Flutter plugins to access Android Lifecycle objects in the plugin's binding.

The purpose of having this plugin instead of exposing an Android Lifecycle object in the engine's Android embedding plugins API is to force plugins to have a pub constraint that signifies the major version of the Android Lifecycle API they expect.

Installation #

Add flutter_plugin_android_lifecycle as a dependency in your pubspec.yaml file.

Example #

Use a FlutterLifecycleAdapter within another Flutter plugin's Android implementation, as shown below:

import androidx.lifecycle.Lifecycle;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding;
import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter;

public class MyPlugin implements FlutterPlugin, ActivityAware {
  public void onAttachedToActivity(ActivityPluginBinding binding) {
    Lifecycle lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(binding);
    // Use lifecycle as desired.

Feedback welcome and Pull Requests are most welcome!

1.0.6 #

  • Make the pedantic dev_dependency explicit.

1.0.5 #

  • Add notice in example this plugin only provides Android Lifecycle API.

1.0.4 #

  • Require Flutter SDK 1.12.13 or greater.
  • Change to avoid reflection.

1.0.3 #

  • Remove the deprecated author: field from pubspec.yaml
  • Require Flutter SDK 1.10.0 or greater.

1.0.2 #

1.0.1 #

  • Register the E2E plugin in the example app.

1.0.0 #

  • Introduces a FlutterLifecycleAdapter, which can be used by other plugins to obtain a Lifecycle reference from a FlutterPluginBinding.


// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Sample flutter_plugin_android_lifecycle usage'),
        body: Center(
            child: Text(
                'This plugin only provides Android Lifecycle API\n for other Android plugins.')),

Use this package as a library

1. Depend on it

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

  flutter_plugin_android_lifecycle: ^1.0.6

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:flutter_plugin_android_lifecycle/flutter_plugin_android_lifecycle.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

1 out of 1 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.


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.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
pedantic ^1.8.0