glue 1.0.6

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

glue

A library that allows you to easily pass a data Model from a one Widget to others using messaging system. This will help avoid passing delegates.

A widget can subscribe to external events using on<Channel, Event>() method.

import 'package:flutter/material.dart';
import 'package:glue/glue.dart';
import 'package:glue_example/channels/counter_channel.dart';
import 'package:glue_example/channels/hello_channel.dart';

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

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

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  BuildContext _context;

  @override
  void initState() {
    Glue.on<HelloChannel, HelloEvent>(_onData);
    super.initState();
  }

  void _onData(event) {
    Scaffold.of(_context).showSnackBar(new SnackBar(
      content: new Text("Hello clicked"),
    ));
  }

  @override
  Widget build(BuildContext context) {
    _context = context;
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Builder(builder: (context) {
          _context = context;
          return Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[CounterView()],
            ),
          );
        }),
        floatingActionButton: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            FloatingActionButton(
              onPressed: () => Glue.emit<CounterChannel>(PlusEvent()),
              tooltip: 'Plus',
              child: Icon(Icons.add),
            ),
            FloatingActionButton(
                onPressed: () => Glue.emit<CounterChannel>(MinusEvent()),
                tooltip: 'Minus',
                child: Icon(Icons.remove)),
          ],
        )
        );
  }

  @override
  void dispose() {
    Glue.off<HelloChannel, HelloEvent>(_onData);
    super.dispose();
  }
}

class CounterView extends StatefulWidget {
  _CounterViewState createState() => _CounterViewState();
}

class _CounterViewState extends State<CounterView> {
  String _text = '';

  @override
  void initState() {
    Glue.on<CounterChannel, PlusEvent>(_onPlusRecieved);
    Glue.on<CounterChannel, MinusEvent>(_onMinusRecieved);
    // subscribe to events
    super.initState();
  }

  void _onPlusRecieved(PlusEvent event) {
    setState(() {
      _text = 'Plus Pushed';
    });
  }

  void _onMinusRecieved(MinusEvent event) {
    setState(() {
      _text = 'Minus Pushed';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      Text(_text),
      RaisedButton(
        child: Text('Push'),
        onPressed: () {
          Glue.emit<HelloChannel>(HelloEvent());
        },
      )
    ]);
  }

  @override
  void dispose() {
    Glue.off<CounterChannel, PlusEvent>(_onPlusRecieved);
    Glue.off<CounterChannel, MinusEvent>(_onMinusRecieved);
    super.dispose();
  }
}

Changelog

1.0.6

  • Refactor

1.0.5

  • Add GlueHub

1.0.4

  • Simplify GlueState

1.0.3

  • Update description

1.0.2

  • Update Readme

1.0.1

  • Add example

1.0.0

  • Initial version

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:glue/glue.dart';
import './channels/counter_channel.dart';
import './channels/hello_channel.dart';

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

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

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  BuildContext _context;

  @override
  void initState() {
    Glue.on<HelloChannel, HelloEvent>(_onData);
    super.initState();
  }

  void _onData(event) {
    Scaffold.of(_context).showSnackBar(new SnackBar(
      content: new Text("Hello clicked"),
    ));
  }

  @override
  Widget build(BuildContext context) {
    _context = context;
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Builder(builder: (context) {
          _context = context;
          return Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[CounterView()],
            ),
          );
        }),
        floatingActionButton: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            FloatingActionButton(
              onPressed: () => Glue.emit<CounterChannel>(PlusEvent()),
              tooltip: 'Plus',
              child: Icon(Icons.add),
            ),
            FloatingActionButton(
                onPressed: () => Glue.emit<CounterChannel>(MinusEvent()),
                tooltip: 'Minus',
                child: Icon(Icons.remove)),
          ],
        )

        // This trailing comma makes auto-formatting nicer for build methods.
        );
  }

  @override
  void dispose() {
    Glue.off<HelloChannel, HelloEvent>(_onData);
    super.dispose();
  }
}

class CounterView extends StatefulWidget {
  _CounterViewState createState() => _CounterViewState();
}

class _CounterViewState extends State<CounterView> {
  String _text = '';

  @override
  void initState() {
    Glue.on<CounterChannel, PlusEvent>(_onPlusRecieved);
    Glue.on<CounterChannel, MinusEvent>(_onMinusRecieved);
    // subscribe to events
    super.initState();
  }

  void _onPlusRecieved(PlusEvent event) {
    setState(() {
      _text = 'Plus Pushed';
    });
  }

  void _onMinusRecieved(MinusEvent event) {
    setState(() {
      _text = 'Minus Pushed';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      Text(_text),
      RaisedButton(
        child: Text('Push'),
        onPressed: () {
          // pushEvent(HelloEvent());
          Glue.emit<HelloChannel>(HelloEvent());
        }, // Send event to parent
      )
    ]);
  }

  @override
  void dispose() {
    Glue.off<CounterChannel, PlusEvent>(_onPlusRecieved);
    Glue.off<CounterChannel, MinusEvent>(_onMinusRecieved);
    super.dispose();
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  glue: ^1.0.6

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:glue/glue.dart';
  
Version Uploaded Documentation Archive
1.0.6 Jan 15, 2019 Go to the documentation of glue 1.0.6 Download glue 1.0.6 archive
1.0.5 Jan 15, 2019 Go to the documentation of glue 1.0.5 Download glue 1.0.5 archive
1.0.4 Jan 15, 2019 Go to the documentation of glue 1.0.4 Download glue 1.0.4 archive
1.0.3 Jan 14, 2019 Go to the documentation of glue 1.0.3 Download glue 1.0.3 archive
1.0.2 Jan 14, 2019 Go to the documentation of glue 1.0.2 Download glue 1.0.2 archive
1.0.1 Jan 14, 2019 Go to the documentation of glue 1.0.1 Download glue 1.0.1 archive
1.0.0 Jan 14, 2019 Go to the documentation of glue 1.0.0 Download glue 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.10
  • Flutter: 1.1.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

6 out of 6 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Format lib/glue.dart.

Run flutter format to format lib/glue.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
rxdart >=0.18.1 <1.0.0 0.20.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