lifecycle_widget 0.0.2

Flutter Android iOS web

Flutter widget with lifecycle methods

Lifecycle widget #

Flutter widget with lifecycle methods GitHub stars Twitter Follow

Installation #

Add dependency to pubspec.yaml

  lifecycle_widget: ^0.0.2

Run in your terminal

flutter packages get

Example #

class TestWidget extends LifecycleWidget {
  final int number;

  const TestWidget({Key key, this.number}) : super(key: key);

  void notify(BuildContext context, String text) {
      content: Text(text),

  void didMount(BuildContext context) {
    notify(context, 'did mount');

  void didUpdate(
    BuildContext context,
    covariant TestWidget oldWidget,
    covariant TestWidget widget,
  ) {
    notify(context, 'update ${oldWidget.number} => ${widget.number}');
    super.didUpdate(context, oldWidget, widget);

  void willUnmount() {
    // no access to context in willUnmount
    print('will unmount');

  Widget build(BuildContext context) {
    return Center(child: Text("number is $number"));

License #

MIT GitHub stars Twitter Follow