Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gurleensethi/notifier
Update any widget, from anywhere at anytime.
https://github.com/gurleensethi/notifier
Last synced: 29 days ago
JSON representation
Update any widget, from anywhere at anytime.
- Host: GitHub
- URL: https://github.com/gurleensethi/notifier
- Owner: gurleensethi
- License: other
- Created: 2019-01-27T18:39:10.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-03T22:34:07.000Z (almost 6 years ago)
- Last Synced: 2024-04-16T12:54:20.854Z (7 months ago)
- Language: Dart
- Size: 60.8 MB
- Stars: 12
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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`.
```yaml
notifier:
```##### 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.
```dart
void main() {
runApp(
NotifierProvider(
child: MyApp(),
),
);
}
```* Register a callback for a certain action in your Widget tree.
```dart
@override
Widget build(BuildContext context) {
return Column(
children: [
Text('Data from Notifier:'),
Notifier.of(context).register('action', (data) {
return Text('${data.data}');
}),
],
);
}
```* From anywhere in your application, call the `notify` method.
```dart
@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!');
},
),
),
);
}
```#### 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.