notifier

Last updated:

0 purchases

notifier Image
notifier Images
Add to Cart

Description:

notifier

notifier #
Update any widget, from anywhere at anytime.
Getting Started #
Inspired from Broadcast Receiver in Android.
Works for both iOS and Android.
Add the following dependency to your project's pubspec.yaml.
notifier: <latest_version>
copied to clipboard
There are two methods that make the core of Notifier.

notify(action, data) - Sending data for a certain action.
register(action, callback) - Listening to data changes for a certain action.

Steps

Add NotifierProvider at root of project's Widget tree.

void main() {
runApp(
NotifierProvider(
child: MyApp(),
),
);
}
copied to clipboard

Register a callback for a certain action in your Widget tree.

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Text('Data from Notifier:'),
Notifier.of(context).register<String>('action', (data) {
return Text('${data.data}');
}),
],
);
}
copied to clipboard

From anywhere in your application, call the 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!');
},
),
),
);
}
copied to clipboard
Things to be aware of!

If a callback is registered on an action with a specific data type T, then passing data with data type other than T in notify method will throw error.

License:

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

Files In This Product:

Customer Reviews

There are no reviews.