eventhandler 1.0.4 copy "eventhandler: ^1.0.4" to clipboard
eventhandler: ^1.0.4 copied to clipboard

discontinued

Simple event handler with singleton constructor. An event is associated with each type of object that it inherits from EventBase.

example/example.dart

import 'package:eventhandler/eventhandler.dart';
import 'package:flutter/material.dart';

import 'events.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'EventHandler Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'EventHandler Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  @override
  void initState() {
    EventHandler()
        .subscribe(_onDecrementCounter)
        .subscribe(_onIncrementCounter);
    super.initState();
  }

  @override
  void dispose() {
    EventHandler()
        .unsubscribe(_onDecrementCounter)
        .unsubscribe(_onIncrementCounter);
    super.dispose();
  }

  void _onIncrementCounter(Increment event) {
    setState(() {
      _counter++;
    });
  }

  void _onDecrementCounter(Decrement event) {
    setState(() {
      _counter--;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                RaisedButton(
                  child: Text("Decrement"),
                  color: Colors.red,
                  onPressed: () {
                    EventHandler().send(Decrement());
                  },
                ),
                RaisedButton(
                  child: Text("Increment"),
                  color: Colors.green,
                  onPressed: () {
                    EventHandler().send(Increment());
                  },
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
2
likes
40
pub points
65%
popularity

Publisher

unverified uploader

Simple event handler with singleton constructor. An event is associated with each type of object that it inherits from EventBase.

Repository (GitLab)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on eventhandler