eventsubscriber 2.0.0
eventsubscriber: ^2.0.0 copied to clipboard

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

example/lib/main.dart

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

import 'counter.dart';

// Create the domain model
var myCounter = 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(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.purple,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text("EventSubscriber Example"),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              //=================================
              // Subscribe to the 'valueChangedEvent' domain event
              // The handler will be run whenever the Event occurs
              EventSubscriber(
                event: myCounter.valueChangedEvent,
                handler: (context, args) => Text(
                  myCounter.value.toString(),
                  style: Theme.of(context).textTheme.headline3,
                ),
              ),
              //=================================

              TextButton(
                onPressed: () => myCounter.increment(), // << ========= increment the counter
                child: Text('Increment Counter'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
120
pub points
39%
popularity

Publisher

aryehoffman.com

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache 2.0 (LICENSE)

Dependencies

event, flutter

More

Packages that depend on eventsubscriber