broadcaster 1.0.4

Flutter Android iOS web

A simple state management for flutter to offer a new option to your application

Broadcaster #

A simple state management for flutter <br/><br/>

Getting started #

You should ensure that you add the broadcaster as a dependency in your flutter project.

read more at how to install

Usage #

A counter app with Broadcaster


class HomePageBroadcaster extends Broadcaster<_BroadcastKeys> {
  // define the broadcast passing a required key and an initital value
  Broadcast<int> get countBroadcast =>
      this.broadcast<int>(_BroadcastKeys.count, initialValue: 0);

  // the increment action
  increment() {
    countBroadcast.value += 1;
  }
}

/// Enum used as the key to broadcasts
enum _BroadcastKeys { count }

Screen Widget

import 'package:broadcaster/broadcaster.dart';
import 'package:flutter/material.dart';
import 'home_page_broadcaster.dart';

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // wrap the page with the provider
    return BroadcasterProvider(
        // creator param
        creator: (context) => HomePageBroadcaster(),
        // builder param with the broadcaster instance
        builder: (context, broadcaster) {
          return Scaffold(
            body: Center(
              // StreamBuilder to consume the stream provided by the broadcast
              child: StreamBuilder<int>(
                  // pass here the broadcast stream
                  stream: broadcaster.countBroadcast.stream,
                  builder: (context, snapshot) {
                    final count = snapshot.data ?? 0;
                    return Text('counter: $count');
                  }),
            ),
            floatingActionButton: FloatingActionButton(
              onPressed: () {
                // call the broadcaster increment action
                broadcaster.increment();
              },
              tooltip: 'Increment',
              child: Icon(Icons.add),
            ),
          );
        });
  }
}

checkout app source at github

1
likes
100
pub points
45%
popularity

A simple state management for flutter to offer a new option to your application

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

everton.build@gmail.com

License

MIT (LICENSE)

Dependencies

flutter, provider, rxdart

More

Packages that depend on broadcaster