flutter_bloc 0.5.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 98
Flutter Bloc Package

Build Status codecov Pub Awesome Flutter License: MIT Gitter


A Flutter package that helps implement the BLoC pattern.

This package is built to work with bloc.

Bloc Widgets

BlocBuilder is a Flutter widget which requires a Bloc and a builder function. BlocBuilder handles building the widget in response to new states. BlocBuilder is very similar to StreamBuilder but has a more simple API to reduce the amount of boilerplate code needed.

BlocProvider is a Flutter widget which provides a bloc to its children via BlocProvider.of(context). It is used as a DI widget so that a single instance of a bloc can be provided to multiple widgets within a subtree.

Usage

Lets take a look at how to use BlocBuilder to hook up a CounterPage widget to a CounterBloc.

class CounterPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final CounterBloc _counterBloc = BlocProvider.of<CounterBloc>(context);

    return Scaffold(
      appBar: AppBar(title: Text('Counter')),
      body: BlocBuilder<CounterEvent, int>(
        bloc: _counterBloc,
        builder: (BuildContext context, int count) {
          return Center(
            child: Text(
              '$count',
              style: TextStyle(fontSize: 24.0),
            ),
          );
        },
      ),
      floatingActionButton: Column(
        crossAxisAlignment: CrossAxisAlignment.end,
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
          Padding(
            padding: EdgeInsets.symmetric(vertical: 5.0),
            child: FloatingActionButton(
              child: Icon(Icons.add),
              onPressed: () {
                _counterBloc.dispatch(Increment());
              },
            ),
          ),
          Padding(
            padding: EdgeInsets.symmetric(vertical: 5.0),
            child: FloatingActionButton(
              child: Icon(Icons.remove),
              onPressed: () {
                _counterBloc.dispatch(Decrement());
              },
            ),
          ),
        ],
      ),
    );
  }
}

At this point we have sucessfully separated our presentational layer from our business logic layer. Notice that the CounterPage widget knows nothing about what happens when a user taps the buttons. The widget simply tells the CounterBloc that the user has pressed either the increment or decrement button.

Dart Versions

  • Dart 2: >= 2.0.0

Examples

  • Simple Counter Example - an example of how to create a CounterBloc to implement the classic Flutter Counter app.
  • Login Flow Example - an example of how to use the bloc and flutter_bloc packages to implement a Login Flow.
  • Infinite List Example - an example of how to use the bloc and flutter_bloc packages to implement an infinite scrolling list.
  • Github Search - an example of how to create a Github Search Application using the bloc and flutter_bloc packages.

Contributors

0.1.0

Initial Version of the library.

  • Includes the ability to connect presentation layer to Bloc by using the BlocBuilder Widget.
  • Includes BlocProvider, a DI widget that allows a single instance of a bloc to be provided to multiple widgets within a subtree.

0.1.1

Minor Updates to Documentation

0.2.0

Updates to BlocBuilder and BlocProvider

  • BlocBuilder does not automatically dispose a Bloc. Developers are now responsible for determining when to call Bloc.dispose()
  • BlocProvider support for of(context) with generics
    • Support for multiple nested BlocProviders with different Bloc Types.

0.2.1

Minor Updates to Documentation

0.3.0

Updated to bloc: ^0.6.0

0.3.1

Minor Updates to Documentation

0.4.0

Updated to bloc: ^0.7.0

0.4.1

Minor Updates to Documentation

0.4.2

BlocProvider performance improvements

0.4.3

BlocBuilder performance improvements

0.4.4

Minor updates to documentation and improved error reporting in BlocProvider

0.4.5

Additional Minor Updates to Documentation

0.4.6

Bug Fixes

  • Fixed bug where BlocBuilder would return initial state instead of the latest state

0.4.7

Minor Updates to Documentation and Examples

0.4.8

Additional BlocProvider performance improvements

0.4.9

Additional BlocBuilder enhancements

  • BlocBuilder no longer has a dependency on RxDart
  • Using bloc: ">=0.7.5 <0.8.0"

0.4.10

Additional BlocBuilder enhancements

  • BlocBuilder no longer filters out States giving developers full control

Minor Updates to Documentation and Examples

0.4.11

Additional Minor Updates to Documentation

0.4.12

Additional Minor Updates to Documentation

0.5.0

Updated to bloc: ^0.8.0

0.5.1

BlocProvider performance improvements

0.5.2

Minor Updates to Documentation

example/README.md

example

A new Flutter project.

Getting Started

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_bloc: ^0.5.2

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:flutter_bloc/flutter_bloc.dart';
  
Version Uploaded Documentation Archive
0.5.2 Jan 22, 2019 Go to the documentation of flutter_bloc 0.5.2 Download flutter_bloc 0.5.2 archive
0.5.1 Jan 13, 2019 Go to the documentation of flutter_bloc 0.5.1 Download flutter_bloc 0.5.1 archive
0.5.0 Jan 11, 2019 Go to the documentation of flutter_bloc 0.5.0 Download flutter_bloc 0.5.0 archive
0.4.12 Jan 7, 2019 Go to the documentation of flutter_bloc 0.4.12 Download flutter_bloc 0.4.12 archive
0.4.11 Dec 21, 2018 Go to the documentation of flutter_bloc 0.4.11 Download flutter_bloc 0.4.11 archive
0.4.10 Dec 21, 2018 Go to the documentation of flutter_bloc 0.4.10 Download flutter_bloc 0.4.10 archive
0.4.9 Dec 19, 2018 Go to the documentation of flutter_bloc 0.4.9 Download flutter_bloc 0.4.9 archive
0.4.8 Dec 15, 2018 Go to the documentation of flutter_bloc 0.4.8 Download flutter_bloc 0.4.8 archive
0.4.7 Dec 12, 2018 Go to the documentation of flutter_bloc 0.4.7 Download flutter_bloc 0.4.7 archive
0.4.6 Dec 10, 2018 Go to the documentation of flutter_bloc 0.4.6 Download flutter_bloc 0.4.6 archive

All 22 versions...

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

We analyzed this package on Jan 22, 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
bloc >=0.8.0 <0.9.0 0.8.1
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
test >=1.3.0 <2.0.0