notification_dispatcher 0.3.1 copy "notification_dispatcher: ^0.3.1" to clipboard
notification_dispatcher: ^0.3.1 copied to clipboard

retracted

Inspired by Apple's NotificationCenter. Passes information around to registered observers.

Build status Pub package License: MIT

Inspired by Apple's NotificationCenter. Passes information around to registered observers.

Installing #

Add the following line to your pubspec.yaml file.

notification_dispatcher: ^0.3.1

Flutter Example #

void main() {
  runApp(const App());
}

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  int _count = 0;

  @override
  void initState() {
    super.initState();
    NotificationDispatcher.instance.addObserver(
      this,
      name: 'observerName',
      callback: (_) => _incrementCount(),
    );
  }

  @override
  void dispose() {
    NotificationDispatcher.instance.removeObserver(this);
    super.dispose();
  }

  void _incrementCount() {
    setState(() {
      _count++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Text(
                'You have pushed the button this many times:',
              ),
              Text(
                '$_count',
                style: Theme.of(context).textTheme.headline4,
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () =>
              NotificationDispatcher.instance.post(name: 'observerName'),
          tooltip: 'Increment',
          child: const Icon(Icons.add),
        ),
      ),
    );
  }
}

Equatable #

To set an Equatable-extended class as an observer, use the NotificationDispatcherEquatableObserverMixin mixin and add the instanceKey property to its props property.

class SomeClass extends Equatable with NotificationDispatcherEquatableObserverMixin {
  @override
  List<Object?> get props => [...super.props, instanceKey];
}
4
likes
0
pub points
17%
popularity

Publisher

unverified uploader

Inspired by Apple's NotificationCenter. Passes information around to registered observers.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on notification_dispatcher