eventsubscriber 1.2.0 copy "eventsubscriber: ^1.2.0" to clipboard
eventsubscriber: ^1.2.0 copied to clipboard

outdated

A Flutter widget that updates (rebuilds) when an Event occurs.

example/eventsubscriber_example.dart

import 'package:flutter/material.dart';
import 'package:event/event.dart';
import 'package:eventsubscriber/eventsubscriber.dart';

// An example domain model of a simple Counter
// Normally in its own module/package
// Included here inline for illustration purposes
class Count {
  int value = 0;
  var onValueChanged = Event(); // declare Event

  void increment() {
    value++;
    // Broadcast that the value has changed
    onValueChanged.broadcast();
  }
}

//////////////////////

// Create the domain model
var myCount = Count();

// Flutter application
// The Count domain value will increment when the button is pressed.
// The updated domain value will be automatically updated in the UI.
void main() => runApp(
      MaterialApp(
        home: Column(
          children: <Widget>[
            // Subscribe to the 'valueChanged' domain event
            EventSubscriber(
              event: myCount.onValueChanged,
              handler: (context, args) => Text(myCount.value.toString()),
            ),
            FlatButton(
              child: Text('Increment'),
              onPressed: () => myCount.increment(),
            )
          ],
        ),
      ),
    );
5
likes
30
pub points
69%
popularity

Publisher

verified publisheraryehoffman.com

A Flutter widget that updates (rebuilds) when an Event occurs.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

event, flutter

More

Packages that depend on eventsubscriber