bus_stop 0.0.1 copy "bus_stop: ^0.0.1" to clipboard
bus_stop: ^0.0.1 copied to clipboard

outdated

A simple Flutter widget that listens to Event Buses.

Bus Stop 🚍🚏 #

A simple Flutter widget that listens to Event Buses.

Learn more about event buses.

Getting Started 🚀 #

Install #

dependencies:
  bus_stop: "^0.0.1"

Import #

import 'package:bus_stop/bus_stop.dart';

Usage 🕹 #

Bus Stop can show a SnackBar and/or change the child Widget based whether the event fires. If doShowSnackBar is set to true, snackBarContext and snackBar must not be null where snackBarContext is a BuildContext that contains a Scaffold.

import 'package:flutter/material.dart';
import 'package:bus_stop/bus_stop.dart';
import 'package:event_bus/event_bus.dart';

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

EventBus bus = EventBus();

/// Event type.
class Event {}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text("Bus Stop Demo"),
        ),
        body: DemoWidget(),
      ),
    );
  }
}

class DemoWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          RaisedButton(
            child: Text("Fire Event"),
            onPressed: () {
              bus.fire(Event());
            },
          ),
          BusStop<Event>(
            eventBus: bus,
            builder: (BuildContext context, bool didEventFire) {
              // Uncomment below code to only use SnackBar
              // return SizedBox();

              if (didEventFire)
                return Text("Fired");
              else
                return Text("Not Fired");
            },
            doShowSnackBar: true,
            snackBarContext: context,
            snackBar: SnackBar(content: Text("Event Fired")),
          ),
        ],
      ),
    );
  }
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A simple Flutter widget that listens to Event Buses.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

event_bus, flutter

More

Packages that depend on bus_stop