flutter_bloc_provider 0.5.0

  • README.md
  • Example
  • Installing
  • Versions
  • 82

flutter_bloc_provider #

This package is part of a number of packages designed to help create BLoC architected code in Dart and Flutter. You can view them all in the repository here.

This README relies on the fact that you have read the main README.

Installation #

  flutter_bloc_provider: <latest_version>

Provider #

A BLoCProvider<BLoC> is an InheritedWidget that allows the BLoC to be accessible to sub widgets. Calling BLoCProvider<BLoC>.of(context) will return the BLoC from the tree.

Make sure you call the dispose method of the BLoCProvider when you are done with it to close any open streams and stop any services.

Disposer #

A BLoCDisposer<BLoC> is a StatefulWidget that wraps a child in a BLoCProvider. The disposer will automatically call the dispose method on the provider when it loses context.

Changelog #

0.5.0 #

  • Add Documentation
  • Refactor
  • Format
  • Add CI
  • Make parameters private by default

0.4.4 #

  • Changed name from flutter_bloc_generator to bloc_generator

0.3.0 #

  • Removed AsyncMapperService
  • Made all mappers streams
  • Split out providers and disposer to flutter_bloc_provider package

0.2.6 #

  • Add MapperService, AsyncMapperService, RequireMapperService and RequireAsyncMapperService

0.2.5 #

  • Currect trigger types to Future from void
  • Make mappers optionally async

0.2.4 #

  • Add TriggeredService

0.2.3 #

  • Allow mappers to return null to not add anything to the output

0.2.2 #

  • Added parameters that can be passed to the BLoC and are accessible to BLoC services

0.2.1 #

  • Make requiring a service require the service type
  • Add BLoCService service that takes an entire BLoC instead of a Stream or Sink

0.2.0 #

  • Make mappers async

0.1.9 #

  • Make template value the only current value stored

0.1.8 #

  • Moved value updater before calling mappers
  • Updating latest values on template

0.1.7 #

  • OutputService automatic listener
  • OutputService automatic subscription disposer

0.1.6 #

  • Remove current data from mappers

0.1.5 #

  • Made services public members

0.1.4 #

  • Changed Service to InputService and added OutputService

0.1.3 #

  • Format code
  • Add example

0.1.2 #

  • Fix latest value updater for initial data

0.1.1 #

  • Change analyzer dependency to ^0.33.0 for compatability

0.1.0 #

  • Initial public release


// Copyright 2019 Callum Iddon
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//     http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:flutter/material.dart';

import 'package:flutter_bloc_provider/flutter_bloc_provider.dart';

import 'package:flutter_bloc_example/bloc.dart';

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

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) => MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      home: BLoCDisposer<TestBLoC>(
          bloc: TestBLoC(maxValue: 20),
          child: const MyHomePage(title: 'Flutter Demo Home Page')));

class MyHomePage extends StatelessWidget {
  final String title;

  const MyHomePage({this.title});

  Widget build(BuildContext context) {
    final TestBLoC bloc = BLoCProvider.of<TestBLoC>(context);
    return Scaffold(
        appBar: AppBar(
          title: Text(title),
        body: Center(
            child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
              const Text('You have pushed the button this many times:'),
                  stream: bloc.counter,
                      (BuildContext context, AsyncSnapshot<String> snapshot) {
                    if (!snapshot.hasData) {
                      return Container();

                    return Column(children: <Widget>[
                          style: Theme.of(context).textTheme.display1),
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                                child: const Text('Reset Counter'),
                                onPressed: () => bloc.setCounter.add(0)),
                                child: const Text('Trigger Url Service'),
                                onPressed: bloc.triggerUrlService)
        floatingActionButton: FloatingActionButton(
            onPressed: () => bloc.addToCounter.add(1),
            tooltip: 'Increment',
            child: const Icon(Icons.add)));

Use this package as a library

1. Depend on it

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

  flutter_bloc_provider: ^0.5.0

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_provider/flutter_bloc_provider.dart';
Version Uploaded Documentation Archive
0.5.0 Mar 27, 2019 Go to the documentation of flutter_bloc_provider 0.5.0 Download flutter_bloc_provider 0.5.0 archive
0.4.0 Jan 1, 2019 Go to the documentation of flutter_bloc_provider 0.4.0 Download flutter_bloc_provider 0.4.0 archive
0.3.0 Dec 31, 2018 Go to the documentation of flutter_bloc_provider 0.3.0 Download flutter_bloc_provider 0.3.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
bloc_annotations 0.5.0 0.5.0
flutter 0.0.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