Update any widget, from anywhere at anytime.
OTHER License
Update any widget, from anywhere at anytime.
Inspired from Broadcast Receiver
in Android.
Works for both iOS
and Android
.
pubspec.yaml
.notifier: <latest_version>
Notifier
.notify(action, data)
- Sending data for a certain action.register(action, callback)
- Listening to data changes for a certain action.NotifierProvider
at root of project's Widget tree.void main() {
runApp(
NotifierProvider(
child: MyApp(),
),
);
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Text('Data from Notifier:'),
Notifier.of(context).register<String>('action', (data) {
return Text('${data.data}');
}),
],
);
}
notify
method.@override
Widget build(BuildContext context) {
Notifier _notifier = NotifierProvider.of(context);
return Scaffold(
body: Center(
RaisedButton(
child: Text('Notify'),
onPressed: () {
_notifier.notify('action', 'Sending data from notfier!');
},
),
),
);
}
T
, then passing data with data type other than T
in notify
method will throw error.