active_observers 0.7.0

  • Readme
  • Changelog
  • Installing
  • 48

active_observers #

Build Status

A new way to create composable UI logic, inspired by React hooks.

Getting Started #

import 'package:active_observers/active_observers.dart'; // 1.import package

class TestObserveState extends StatefulWidget with DetailedLifecyleInState {  // mixin is optional
  final Stream<String> stream;

  _TestObserveStateState createState() => _TestObserveStateState();

class _TestObserveStateState extends State<TestObserveState>
    with ActiveObservers { // 2. Add a mixin to your State
  assembleActiveObservers() {
    // 3. Setup active observers in assembleActiveObservers
    // codes in this method will be executed on hot reload
      // subscription will be automatically restarted when any value in values updates
        value = v;
    }).cancel, values: ()=> []);

  String value;

  Widget build(BuildContext context) {
    return Text(value, textDirection: TextDirection.ltr);

Under construction.

Please refer to ./test/src for more active observers.


  • initial release


  • Add ActiveObserver interface


  • Add observeStream


  • Add observeListenable & observeValueListenableState


  • Add dependency update detection logic


  • Major rewrite
  • Remove dependencies other than Flutter
  • Active observers should be called in State's constructor


  • Make active observers run in the expected order


  • Always restart effect on reassemble


  • Add assembleActiveObservers slot


  • Clean active observers on reassemble
  • Now all active observers must be placed in assembleActiveObservers


  • Use implicit this in active observers


  • Mark assembleActiveObservers as virtual


  • Update observeLifecycle interface


  • Add example


  • Add didSetState lifecycle
  • observeEffect now receive a function to decide when to restart
  • observeEffect now may restart effect in setState
  • Add observePaint observer


  • Add observeContext and observeInheritedWidget
  • Remove some observers
  • Rename observeEffect to observeUpdate
  • Adjust reassemble order
  • Add optional widget mixin DetailedLifecycleInstate
  • Improve performance

Use this package as a library

1. Depend on it

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

  active_observers: ^0.7.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:active_observers/active_observers.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 Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.2
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/src/observe_inherited_widget.dart. (-1 points)

Analysis of lib/src/observe_inherited_widget.dart reported 2 hints:

line 11 col 22: 'inheritFromWidgetOfExactType' is deprecated and shouldn't be used. Use dependOnInheritedWidgetOfExactType instead. This feature was deprecated after v1.12.1..

line 14 col 37: 'inheritFromWidgetOfExactType' is deprecated and shouldn't be used. Use dependOnInheritedWidgetOfExactType instead. This feature was deprecated after v1.12.1..

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and active_observers.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
collection ^1.14.11 1.14.11 1.14.12
flutter 0.0.0
Transitive dependencies
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies