flutter_lifecycle 0.2.0 copy "flutter_lifecycle: ^0.2.0" to clipboard
flutter_lifecycle: ^0.2.0 copied to clipboard

Get access to Flutter's life cycle on StatelessWidgets. It adds the ability to run onInit and onDispose to StatelessWidget

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

2
likes
40
pub points
29%
popularity

Publisher

unverified uploader

Get access to Flutter's life cycle on StatelessWidgets. It adds the ability to run onInit and onDispose to StatelessWidget

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_lifecycle