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>
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(),
    ),
  );
}
  • 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}');
        }),
      ],
    );
  }
  • 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!');
          },
        ),
      ),
    );
  }

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.

Libraries

main_notifier
notifier
notifier_data
notifier_impl
notifier_provider

Dart

dart:ui
Built-in types and core primitives for a Flutter application. [...]

Core

dart:async
Support for asynchronous programming, with classes such as Future and Stream. [...]
dart:collection
Classes and utilities that supplement the collection support in dart:core. [...]
dart:convert
Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
dart:core
Built-in types, collections, and other core functionality for every Dart program. [...]
dart:developer
Interact with developer tools such as the debugger and inspector. [...]
dart:math
Mathematical constants and functions, plus a random number generator. [...]
dart:typed_data
Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]

VM

dart:io
File, socket, HTTP, and other I/O support for non-web applications. [...]
dart:isolate
Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]