bloc_provider 0.5.0+3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 93

bloc_provider #

Provides BLoC(Business Logic Component) to descendant widget (O(1)), and the bloc is disposed automatically by the state which the bloc_provider holds internally.

Usage #

1. Define some BLoC like this: #

class CounterBloc implements Bloc {
  final _countController = BehaviorSubject<int>(seedValue: 0);
  final _incrementController = PublishSubject<void>();

  CounterBloc() {
    _incrementController
        .scan<int>((sum, _v, _i) => sum + 1, 0)
        .pipe(_countController);
  }

  ValueObservable<int> get count => _countController;
  Sink<void> get increment => _incrementController.sink;

  @override
  void dispose() async {
    await _incrementController.close();
    await _countController.close();
  }
}

2. Provide the bloc by using BlocProvider and access the bloc at subtree: #

void main() => runApp(
      // Create and provide the bloc.
      BlocProvider<CounterBloc>(
        creator: (_context, _bag) => CounterBloc(),
        child: App(),
      ),
    );

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Access the bloc with O(1) computation complexity.
    final bloc = BlocProvider.of<CounterBloc>(context);
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: StreamBuilder<int>(
            stream: bloc.count,
            initialData: bloc.count.value,
            builder: (context, snap) => Text(
                  'count: ${snap.data}',
                  style: Theme.of(context).textTheme.title,
                ),
          ),
        ),
        floatingActionButton: FloatingActionButton(
          child: const Icon(Icons.add),
          onPressed: () => bloc.increment.add(null),
        ),
      ),
    );
  }
}
  • Computational complexity of of method, which is used for accessing the bloc is O(1).
  • Provided bloc will be disposed when the inner state is disposed 👍

Examples #

Technical explanation #

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.5.0 #

  • Add BlocProviderTree Widget (#4, #5)
    • Converts the BlocProvider list into a tree of nested BlocProvider widgets.

0.4.0 #

  • Change to BlocProvider.fromBloc from BlocProvider.unmanaged
  • Add BlocProvider.fromBlocContext constructor

0.3.0 #

  • Add BlocProvider.unmanaged constructor

0.2.1 #

  • Update README

0.2.0 #

  • Update documentation

0.1.0 #

  • Initial Release

Use this package as a library

1. Depend on it

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


dependencies:
  bloc_provider: ^0.5.0+3

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:bloc_provider/bloc_provider.dart';
  
Version Uploaded Documentation Archive
0.5.0+3 Mar 9, 2019 Go to the documentation of bloc_provider 0.5.0+3 Download bloc_provider 0.5.0+3 archive
0.5.0+2 Feb 26, 2019 Go to the documentation of bloc_provider 0.5.0+2 Download bloc_provider 0.5.0+2 archive
0.5.0+1 Feb 26, 2019 Go to the documentation of bloc_provider 0.5.0+1 Download bloc_provider 0.5.0+1 archive
0.5.0 Feb 26, 2019 Go to the documentation of bloc_provider 0.5.0 Download bloc_provider 0.5.0 archive
0.4.0+3 Feb 26, 2019 Go to the documentation of bloc_provider 0.4.0+3 Download bloc_provider 0.4.0+3 archive
0.4.0+2 Feb 26, 2019 Go to the documentation of bloc_provider 0.4.0+2 Download bloc_provider 0.4.0+2 archive
0.4.0+1 Feb 26, 2019 Go to the documentation of bloc_provider 0.4.0+1 Download bloc_provider 0.4.0+1 archive
0.4.0 Feb 26, 2019 Go to the documentation of bloc_provider 0.4.0 Download bloc_provider 0.4.0 archive
0.3.1 Feb 26, 2019 Go to the documentation of bloc_provider 0.3.1 Download bloc_provider 0.3.1 archive
0.3.0 Feb 26, 2019 Go to the documentation of bloc_provider 0.3.0 Download bloc_provider 0.3.0 archive

All 36 versions...

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

We analyzed this package on Apr 25, 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

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.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
Dev dependencies
flutter_test
rxdart any