flutter_observer 2.0.0 copy "flutter_observer: ^2.0.0" to clipboard
flutter_observer: ^2.0.0 copied to clipboard

similar android BroadcastReceiver andd ios NSNotification,Used to notify the page to refresh.This is a pure dart language development package

flutter_observer #

android BroadcastReceiver iOS NSNotification

Supported Platforms

  • Android
  • iOS

How to Use #

# add this line to your dependencies
flutter_observer: ^2.0.0
import 'package:flutter_observer/Observable.dart';
import 'package:flutter_observer/Observer.dart';
///Accept notification page
class APageState extends State<APage> with Observer{
  @override
    void initState() {
      Observable.instance.addObserver(this);
      super.initState();
    }
 @override
  void dispose() {
    Observable.instance.removeObserver(this);
    super.dispose();
  }
  @override
   update(Observable observable,String notifyName, Map map) {
    ///do your work
      setState(() {
      });
    }
}

///Send notification page
class CPage extends StatefulWidget {
 @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Container(height: 100, child: Center(child: Text("C页面,负责发送通知"))),
          RaisedButton(
              onPressed: () {
                ///Called where you need to send a notification
                Map map = Map();
                map["background"] = Colors.green;
                ///Observable.instance.notifyObservers(null);
                Observable.instance.notifyObservers([
                  "APageState",
                ], notifyName : "可以通过notifyName判断通知",map: map);
              },
              child: Text("只发送通知到APageState修改背景色")),
        ],
      ),
    );
  }
}

Observable property description
stateNames List or null
map {"id":"1"}
8
likes
150
pub points
87%
popularity

Publisher

unverified uploader

similar android BroadcastReceiver andd ios NSNotification,Used to notify the page to refresh.This is a pure dart language development package

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on flutter_observer