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

outdated

类似android BroadcastReceiver 和 ios NSNotification,用于通知页面刷新。这是一个纯dart语言开发的package

flutter_observer #

android BroadcastReceiver iOS NSNotification

Supported Platforms

  • Android
  • iOS

How to Use #

# add this line to your dependencies
flutter_observer: ^1.0.2
import 'package:flutter_observer/Observable.dart';
import 'package:flutter_observer/Observer.dart';
///接受通知页面
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
   updata(Observable observable, Map map) {
    ///do your work
      if(map != null && map.containsKey("background")){
        MaterialColor bc = map["background"];
      }else if(map != null && map.containsKey("notifyText")){
        String notifyText = map["notifyText"];
      }else{
        print("通知所有Observer");
      }
      setState(() {
      });
    }
}

///发送通知页面
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",
                ], map: map);
              },
              child: Text("只发送通知到APageState修改背景色")),
        ],
      ),
    );
  }
}

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

Publisher

unverified uploader

类似android BroadcastReceiver 和 ios NSNotification,用于通知页面刷新。这是一个纯dart语言开发的package

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_observer