flutter_lifecycle 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

flutter_lifecycle #

Get access to Flutter's life cycle on StatelessWidgets

Getting Started #

You should ensure that you add the flutter_lifecycle as a dependency in your flutter project.

read more at how to install

Usage #


import 'package:flutter/material.dart';
import 'package:flutter_lifecycle/flutter_lifecycle.dart';

class HomePage extends StatelessWidget {
  //on init function
  //pass to the LifeCycleBuilder
  Dispose _onInit(BuildContext context) {
    //good to showDialogs only when the widget init
    showDialog(
        context: context,
        builder: (context) => AlertDialog(
              content: Text("Hello from init"),
            ));

    //if you need do something on dispose
    //return a Function()
    return () {
      print("on dispose");
    };
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: LifeCycleBuilder(
        //set on init function
        onInit: _onInit,
        //builder function
        builder: (context) {
          return Center(
            child: Text("Home page"),
          );
        },
      ),
    );
  }
}

checkout app source at github

[0.2.0] - Aug 26, 2019

  • Renamed LifeCycleWidget to LifeCycleBuilder

[0.1.2] - Aug 13, 2019

  • OnInitAsync

[0.1.1] - Aug 13, 2019

  • Readme instructions

[0.1.0] - Aug 13, 2019

  • Ready to production

[0.0.1] - Aug 13, 2019

  • onInit Function
  • onDispose Function

example/README.md

example #

flutter_lifecycle example

Getting Started #

example/home_page.dart


import 'package:flutter/material.dart';
import 'package:flutter_lifecycle/flutter_lifecycle.dart';

class HomePage extends StatelessWidget {
  //on init function
  //pass to the LifeCycleBuilder
  Dispose _onInit(BuildContext context) {
    //good to showDialogs only when the widget init
    showDialog(
        context: context,
        builder: (context) => AlertDialog(
              content: Text("Hello from init"),
            ));

    //if you need do something on dispose
    //return a Function()
    return () {
      print("on dispose");
    };
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: LifeCycleBuilder(
        //set on init function
        onInit: _onInit,
        //builder function
        builder: (context) {
          return Center(
            child: Text("Home page"),
          );
        },
      ),
    );
  }
}

checkout app source at github

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_lifecycle: ^0.2.0

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_lifecycle/flutter_lifecycle.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
50
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]
75
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

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