flutter_bloc_monitor 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

A package to monitor all your BloC activities. You can monitor things like what events were added in which order. You can see all both the transitions that happened and errors that were thrown.

Basic Usage #

The package is quite straightforward to be used. Just create a FlutterBlocMonitorDelegate and pass it to your BlocSupervisor.

void main() {
  BlocSupervisor.delegate = FlutterBlocMonitorDelegate();
  runApp(MyApp());
}

Just by doing that and all your BloCs will start to be tracked.

This package expose all the actions, transitions and errors in static variables so you can consume ir anywhere you like.

FlutterBlocMonitorDelegate.events
FlutterBlocMonitorDelegate.transitions
FlutterBlocMonitorDelegate.errors

If you ant to see this kind of information in a nicer way you can navigate to a page that shows these info. To do that just do:

Navigator.of(context).push(
      MaterialPageRoute(
        builder: (_) => FlutterBlocMonitorPage(),
      ),
    )

Example

Advanced usage #

If you want to do your own kind of stuff when an event, transition and error occur you can pass the callback function to the onEventFunc, onTransitionFunc and onErrorFunc parameters.

void main() {
  BlocSupervisor.delegate = FlutterBlocMonitorDelegate(
    onEventFunc: (bloc, event) => print(event),
    onTransitionFunc: (bloc, transition) => print(transition),
    onErrorFunc: (bloc, error, stacktrace) => print(error),
  );
  runApp(MyApp());
}

Todo #

  • [ ] Tests

Features and Bugs #

Please sugest new features and report bugs on issue tracker.

[1.0.1] #

Updating dependencies and adapting sample to use bloc 5

[1.0.0+1] #

Adding health suggestions

[1.0.0] #

First fully functional release

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_monitor/flutter_bloc_monitor.dart';

import 'bloc/blocs.dart';
import 'bloc/red/red_bloc.dart';

void main() {
  Bloc.observer = FlutterBlocMonitorDelegate(
    onEventFunc: (bloc, event) => print(event),
    onTransitionFunc: (bloc, transition) => print(transition),
    onErrorFunc: (bloc, error, stacktrace) => print(error),
  );
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: MultiBlocProvider(
          providers: [
            BlocProvider<RedBloc>(
              create: (_) => RedBloc(),
            ),
            BlocProvider<BlueBloc>(
              create: (_) => BlueBloc(),
            ),
            BlocProvider<GreenBloc>(
              create: (_) => GreenBloc(),
            ),
          ],
          child: SampleWidget(),
        ),
      ),
    );
  }
}

class SampleWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: <Widget>[
            BlocBuilder<RedBloc, RedState>(
              builder: (_, state) => Container(
                height: 100,
                child: Center(
                  child: RaisedButton(
                    child: Text(
                      'Add RedBloc Event',
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                    onPressed: () => context.bloc<RedBloc>().add(RedEvent1()),
                    color: Colors.red,
                  ),
                ),
              ),
            ),
            BlocBuilder<BlueBloc, BlueState>(
              builder: (_, state) => Container(
                height: 100,
                child: Center(
                  child: RaisedButton(
                    child: Text(
                      'Add BlueBloc Event',
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                    onPressed: () => context.bloc<BlueBloc>().add(BlueEvent1()),
                    color: Colors.blue,
                  ),
                ),
              ),
            ),
            BlocBuilder<GreenBloc, GreenState>(
              builder: (_, state) => Container(
                height: 100,
                child: Center(
                  child: RaisedButton(
                    child: Text(
                      'Add GreenBloc Event',
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                    onPressed: () =>
                        context.bloc<GreenBloc>().add(GreenEvent1()),
                    color: Colors.green,
                  ),
                ),
              ),
            ),
            SizedBox(height: 30),
            Container(
              height: 100,
              child: RaisedButton(
                color: Theme.of(context).primaryColor,
                child: Text('See Bloc Monitor Page'),
                onPressed: () => Navigator.of(context).push(
                  MaterialPageRoute(
                    builder: (_) => FlutterBlocMonitorPage(),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_bloc_monitor: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub 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_monitor/flutter_bloc_monitor.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
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]
78
Learn more about scoring.

We analyzed this package on Jul 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flutter_bloc_monitor that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
convex_bottom_bar ^2.2.3 2.2.5
flutter 0.0.0
flutter_bloc ^5.0.0 5.0.1
Transitive dependencies
bloc 5.0.1
collection 1.14.12 1.14.13
cubit 0.1.2 0.2.0-dev.1
flutter_cubit 0.1.1 0.2.0-dev.1
meta 1.1.8 1.2.2
nested 0.0.4
provider 4.3.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test