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