active_observers 0.7.0
active_observers: ^0.7.0

Flutter Android iOS web

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

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
  TestObserveState(this.stream);
  
  final Stream<String> stream;

  @override
  _TestObserveStateState createState() => _TestObserveStateState();
}

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

  String value;

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

Under construction.

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

0
likes
90
pub points
0%
popularity

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

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

bob432091@gmail.com

License

MIT (LICENSE)

Dependencies

collection, flutter

More

Packages that depend on active_observers