bloc_generic_streams 2.0.0
bloc_generic_streams: ^2.0.0 copied to clipboard

A Flutter package to implement Didier Boelens's BlocProvider and simplified use of Stream using Dart's Generics.

example/lib/main.dart

import 'package:example/home_bloc.dart';
import 'package:flutter/material.dart';
import 'package:bloc_generic_streams/bloc_generic_streams.dart';

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

class HomeScreen extends StatelessWidget {
  final HomeBloc _bloc = HomeBloc();

  @override
  Widget build(BuildContext context) {
    return BlocProvider<HomeBloc>(
      blocBuilder: () => _bloc,
      child: Scaffold(
        appBar: AppBar(title: Text('Home Screen')),
        floatingActionButton: FloatingActionButton(
          onPressed: _bloc.incrementCounter,
          child: Icon(Icons.add),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Click on the FAB button to increment the value above:'),
              StreamBuilder<int>(
                initialData: _bloc.counter,
                stream: _bloc.counterStream.stream,
                builder: (_, AsyncSnapshot<int> snapshot) {
                  return Text('${snapshot.data}');
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: HomeScreen());
  }
}
3
likes
120
pub points
54%
popularity

A Flutter package to implement Didier Boelens's BlocProvider and simplified use of Stream using Dart's Generics.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

fellipedmmalta@gmail.com

License

MIT (LICENSE)

Dependencies

flutter, rxdart

More

Packages that depend on bloc_generic_streams