relay 0.1.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 73

Relay #

Library which uses modified BLoC pattern to listen to multiple updates in single builder widget. #

Example #

Through simple implementation you can relay update from station and subscribe via RelayBuilder.

RelayBuilder Widget can listen to more than one updates you can provide observers parameter a list of updates.

Like in below example,

  • first relay builder widget observes only on counter.
  • second relay builder widget observes on both counter and name.
enum ExampleUpdate { counter, name }

class ExampleStation extends Station<ExampleUpdate> {
  int counter = 0;
  String name = '';

  void increment() {
    counter++;
    relay(ExampleUpdate.counter);
  }

  void updateName(String text) {
    name = text;
    relay(ExampleUpdate.name);
  }
}

class Example extends StatefulWidget {
  ExampleState createState() => ExampleState();
}

class ExampleState extends State<Example> {
  ExampleStation station;

  @override
  void initState() {
    super.initState();
    station = ExampleStation();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Center(
          child: Column(
            children: <Widget>[
              RelayBuilder<ExampleStation, ExampleUpdate>(
                station: station,
                observers: [ExampleUpdate.counter],
                builder: (context, station) => Text('${station.counter}'),
              ),
              RelayBuilder<ExampleStation, ExampleUpdate>(
                station: station,
                observers: [ExampleUpdate.name, ExampleUpdate.counter],
                builder: (context, station) =>
                    Text('${station.name} : ${station.counter}'),
              ),
              TextField(
                onChanged: station.updateName,
                decoration: InputDecoration(
                  labelText: 'Name',
                ),
              )
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: station.increment,
        child: Icon(Icons.add),
      ),
    );
  }
}

Example With Use of Provider. #

  • main.dart

    Wrap Material App with Provider

    Provider(
      child : MaterialApp(
          ...
      ) , 
    );
  • Widget

Extend ProviderWidget and ProviderState then you can access the station object in deep hierarchies also.

[0.0.1] - Initial Release.

[0.1.0] - Stable Release

Added Support for listening the updates via onUpdate method. It can be used for pushing routes or showing snackbar. See More in Example

[0.1.2] - New Function

Added Support for relaying more than one updates at a time via relayMultiple() function.

[0.1.4] - Major Bug Fixes;

Bug of re-initialization of station object fixed.

example/main.dart

import 'package:flutter/material.dart';
import '../lib/relay.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Provider(
      child: MaterialApp(
        title: 'Relay Example',
        home: Example(),
      ),
    );
  }
}

enum ExampleUpdate { counter, name, message }

class ExampleStation extends Station<ExampleUpdate> {
  int counter = 0;
  String name = '';
  String snackBarMessage;

  void increment() {
    if (counter < 10) {
      counter++;
      relay(ExampleUpdate.counter);
    } else {
      snackBarMessage = 'Maximum Limit Reached';
      relay(ExampleUpdate.message);
    }
  }

  void updateName(String text) {
    name = text;
    relay(ExampleUpdate.name);
  }
}

class Example extends ProviderWidget<ExampleStation> {
  Example() : super(builder: () => ExampleStation());

  ExampleState createState() => ExampleState();
}

class ExampleState
    extends ProviderState<Example, ExampleStation, ExampleUpdate> {
  @override
  void onUpdate(ExampleUpdate update) {
    super.onUpdate(update);
    if (update == ExampleUpdate.message)
      Scaffold.of(context)
          .showSnackBar(SnackBar(content: Text(station.snackBarMessage)));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Center(
          child: Column(
            children: <Widget>[
              RelayBuilder<ExampleStation, ExampleUpdate>(
                station: station,
                observers: [ExampleUpdate.counter],
                builder: (context, station) => Text('${station.counter}'),
              ),
              RelayBuilder<ExampleStation, ExampleUpdate>(
                station: station,
                observers: [ExampleUpdate.name, ExampleUpdate.counter],
                builder: (context, station) =>
                    Text('${station.name} : ${station.counter}'),
              ),
              TextField(
                onChanged: station.updateName,
                decoration: InputDecoration(
                  labelText: 'Name',
                ),
              )
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: station.increment,
        child: Icon(Icons.add),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  relay: ^0.1.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:relay/relay.dart';
  
Version Uploaded Documentation Archive
0.1.4 Feb 18, 2019 Go to the documentation of relay 0.1.4 Download relay 0.1.4 archive
0.1.3 Feb 18, 2019 Go to the documentation of relay 0.1.3 Download relay 0.1.3 archive
0.1.2 Feb 18, 2019 Go to the documentation of relay 0.1.2 Download relay 0.1.2 archive
0.1.1 Feb 18, 2019 Go to the documentation of relay 0.1.1 Download relay 0.1.1 archive
0.1.0 Feb 18, 2019 Go to the documentation of relay 0.1.0 Download relay 0.1.0 archive
0.0.6 Feb 17, 2019 Go to the documentation of relay 0.0.6 Download relay 0.0.6 archive
0.0.5 Feb 17, 2019 Go to the documentation of relay 0.0.5 Download relay 0.0.5 archive
0.0.4 Feb 17, 2019 Go to the documentation of relay 0.0.4 Download relay 0.0.4 archive
0.0.3 Feb 17, 2019 Go to the documentation of relay 0.0.3 Download relay 0.0.3 archive
0.0.2 Feb 17, 2019 Go to the documentation of relay 0.0.2 Download relay 0.0.2 archive

All 11 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
46
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]
73
Learn more about scoring.

We analyzed this package on Mar 6, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.3.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test