LCOV - code coverage report
Current view: top level - src - multi_bloc_listener.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 2 2 100.0 %
Date: 2021-10-05 22:30:28 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/widgets.dart';
       2             : import 'package:flutter_bloc/src/bloc_listener.dart';
       3             : import 'package:provider/provider.dart';
       4             : 
       5             : /// {@template multi_bloc_listener}
       6             : /// Merges multiple [BlocListener] widgets into one widget tree.
       7             : ///
       8             : /// [MultiBlocListener] improves the readability and eliminates the need
       9             : /// to nest multiple [BlocListener]s.
      10             : ///
      11             : /// By using [MultiBlocListener] we can go from:
      12             : ///
      13             : /// ```dart
      14             : /// BlocListener<BlocA, BlocAState>(
      15             : ///   listener: (context, state) {},
      16             : ///   child: BlocListener<BlocB, BlocBState>(
      17             : ///     listener: (context, state) {},
      18             : ///     child: BlocListener<BlocC, BlocCState>(
      19             : ///       listener: (context, state) {},
      20             : ///       child: ChildA(),
      21             : ///     ),
      22             : ///   ),
      23             : /// )
      24             : /// ```
      25             : ///
      26             : /// to:
      27             : ///
      28             : /// ```dart
      29             : /// MultiBlocListener(
      30             : ///   listeners: [
      31             : ///     BlocListener<BlocA, BlocAState>(
      32             : ///       listener: (context, state) {},
      33             : ///     ),
      34             : ///     BlocListener<BlocB, BlocBState>(
      35             : ///       listener: (context, state) {},
      36             : ///     ),
      37             : ///     BlocListener<BlocC, BlocCState>(
      38             : ///       listener: (context, state) {},
      39             : ///     ),
      40             : ///   ],
      41             : ///   child: ChildA(),
      42             : /// )
      43             : /// ```
      44             : ///
      45             : /// [MultiBlocListener] converts the [BlocListener] list into a tree of nested
      46             : /// [BlocListener] widgets.
      47             : /// As a result, the only advantage of using [MultiBlocListener] is improved
      48             : /// readability due to the reduction in nesting and boilerplate.
      49             : /// {@endtemplate}
      50             : class MultiBlocListener extends MultiProvider {
      51             :   /// {@macro multi_bloc_listener}
      52           1 :   MultiBlocListener({
      53             :     Key? key,
      54             :     required List<BlocListenerSingleChildWidget> listeners,
      55             :     required Widget child,
      56           1 :   }) : super(key: key, providers: listeners, child: child);
      57             : }

Generated by: LCOV version 1.15