eventsubscriber 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new60

EventSubscriber #

Pub Package

A Flutter widget that supports subscribing to one or more named EventNotifier events.

The EventSubscriber widget will be notified and rebuilt when a subscribed event occurs, allowing some changing aspect of a problem domain model to be displayed in your Flutter user interface.

See also #

EventNotifier - broadcasts named events to interested subscribers.

Dependencies #

  • Flutter - This Dart package has a dependency on the Flutter framework.
  • EventNotifier - Indirect. Typically one will 'mixin' EventNotifier with your domain model. Your domain model would then be the dependency.

Usage #

A simple example:

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

// An example domain model
// Normally in its own module/package
// Included here for illustration purposes
// EventNotifier is 'mixed-in' with the domain model
class Count with EventNotifier {
  int value = 0;
  void increment() {
    value++;
    notify('valueChanged'); // notify subscribers
  }
}

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

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

// Flutter application
void main() => runApp(
    MaterialApp(
        home: Column(
            children: <Widget>[
            // Subscribe to the 'valueChanged' model event
            EventSubscriber(      // <<===
                model: myCount,
                eventNames: ['valueChanged'],
                builder: (context) => Text(myCount.value.toString()),
            ),
            FlatButton(
                child: Text('Increment'),
                onPressed: () => myCount.increment(),
            )
            ],
        ),
    ),
);

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

Version 1.0.3 (2020-01-14) #

  • Updated to support latest EventNotifier (1.0.5), which includes support for a subscriber to optionally expect some 'argument/s' as a Map.

Version 1.0.2 (2020-01-13) #

  • Fixed LICENSE reference to package

Version 1.0.1 (2020-01-13) #

  • Fixed formatting and documentation errors.

Version 1.0.0 (2020-01-13) #

  • Initial release

example/eventsubscriber_example.dart

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

// An example domain model
// Normally in its own module/package
// Included here for illustration purposes
class Count with EventNotifier {
  int value = 0;
  void increment() {
    value++;
    notify('valueChanged'); // notify subscribers
  }
}

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

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

// Flutter application
void main() => runApp(
      MaterialApp(
        home: Column(
          children: <Widget>[
            // Subscribe to the 'valueChanged' model event
            EventSubscriber(
              model: myCount,
              eventNames: ['valueChanged'],
              builder: (context) => Text(myCount.value.toString()),
            ),
            FlatButton(
              child: Text('Increment'),
              onPressed: () => myCount.increment(),
            )
          ],
        ),
      ),
    );

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  eventsubscriber: ^1.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:eventsubscriber/eventsubscriber.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
19
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/src/eventsubscriber.dart.

Run flutter format to format lib/src/eventsubscriber.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
eventnotifier ^1.0.5 1.0.5
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
pedantic ^1.8.0
test ^1.6.0