flutter_observer

Creator: coderz1093

Last updated:

Add to Cart

Description:

flutter observer

flutter_observer #
android BroadcastReceiver iOS NSNotification

Supported Platforms

Android
iOS


How to Use #
# add this line to your dependencies
flutter_observer: ^2.0.0
copied to clipboard
import 'package:flutter_observer/Observable.dart';
import 'package:flutter_observer/Observer.dart';
copied to clipboard
///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修改背景色")),
],
),
);
}
}

copied to clipboard



Observable property
description




stateNames
List or null


map
{"id":"1"}

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.