refactor(bloc_helper): docs + nullable multiprovider attributes
This commit is contained in:
		
							parent
							
								
									72b27b27ee
								
							
						
					
					
						commit
						468aa72635
					
				| @ -16,12 +16,10 @@ | ||||
|  * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| --> | ||||
| 
 | ||||
| # Flutter - BloC Helper | ||||
| # BloC Helper | ||||
| 
 | ||||
| <p align="left"> | ||||
|   <a href="https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis"> | ||||
|     <img src="https://img.shields.io/badge/Style-Wyatt%20Analysis-blue.svg?style=flat-square" alt="Style: Wyatt Analysis" /> | ||||
|   </a> | ||||
|   <a href="https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis"><img src="https://img.shields.io/badge/Style-Wyatt%20Analysis-blue.svg?style=flat-square" alt="Style: Wyatt Analysis" /></a> | ||||
|   <img src="https://img.shields.io/badge/SDK-Flutter-blue?style=flat-square" alt="SDK: Flutter" /> | ||||
| </p> | ||||
| 
 | ||||
|  | ||||
| @ -17,7 +17,12 @@ | ||||
| import 'package:flutter/widgets.dart'; | ||||
| import 'package:flutter_bloc/flutter_bloc.dart'; | ||||
| 
 | ||||
| /// A utility class that provides a way to create a [BlocProvider] or | ||||
| /// [RepositoryProvider] with a [Bloc] or Repository that is already | ||||
| /// available in the widget tree. | ||||
| abstract class SmartProvider { | ||||
|   /// Creates a [BlocProvider] with a [Bloc] that is possibly already | ||||
|   /// available in the widget tree. | ||||
|   static BlocProvider<Bloc> | ||||
|       bloc<Bloc extends BlocBase<State>, State extends Object>( | ||||
|     BuildContext context, { | ||||
| @ -45,6 +50,8 @@ abstract class SmartProvider { | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   /// Creates a [RepositoryProvider] with a Repository that is possibly | ||||
|   /// already available in the widget tree. | ||||
|   static RepositoryProvider<Repository> repo<Repository>( | ||||
|     BuildContext context, { | ||||
|     required Repository Function(BuildContext) create, | ||||
|  | ||||
| @ -77,9 +77,9 @@ import 'package:flutter_bloc/flutter_bloc.dart'; | ||||
| class MultiProvider extends StatelessWidget { | ||||
|   /// {@macro multi_provider} | ||||
|   const MultiProvider({ | ||||
|     required this.repositoryProviders, | ||||
|     required this.blocProviders, | ||||
|     required this.child, | ||||
|     this.repositoryProviders = const <RepositoryProvider<dynamic>>[], | ||||
|     this.blocProviders = const <BlocProvider>[], | ||||
|     super.key, | ||||
|   }); | ||||
| 
 | ||||
| @ -88,7 +88,26 @@ class MultiProvider extends StatelessWidget { | ||||
|   final Widget child; | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) => MultiRepositoryProvider( | ||||
|   Widget build(BuildContext context) { | ||||
|     if (repositoryProviders.isEmpty && blocProviders.isEmpty) { | ||||
|       return child; | ||||
|     } | ||||
| 
 | ||||
|     if (repositoryProviders.isEmpty) { | ||||
|       return MultiBlocProvider( | ||||
|         providers: blocProviders, | ||||
|         child: child, | ||||
|       ); | ||||
|     } | ||||
| 
 | ||||
|     if (blocProviders.isEmpty) { | ||||
|       return MultiRepositoryProvider( | ||||
|         providers: repositoryProviders, | ||||
|         child: child, | ||||
|       ); | ||||
|     } | ||||
| 
 | ||||
|     return MultiRepositoryProvider( | ||||
|       providers: repositoryProviders, | ||||
|       child: MultiBlocProvider( | ||||
|         providers: blocProviders, | ||||
| @ -96,3 +115,4 @@ class MultiProvider extends StatelessWidget { | ||||
|       ), | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -6,18 +6,16 @@ version: 2.0.0 | ||||
| publish_to: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub | ||||
| 
 | ||||
| environment: | ||||
|   sdk: '>=2.17.0 <3.0.0' | ||||
|   sdk: ">=2.17.0 <3.0.0" | ||||
| 
 | ||||
| dependencies: | ||||
|   flutter: | ||||
|     sdk: flutter | ||||
|   flutter: { sdk: flutter } | ||||
| 
 | ||||
|   flutter_bloc: ^8.1.1 | ||||
|   equatable: ^2.0.5 | ||||
| 
 | ||||
| dev_dependencies: | ||||
|   flutter_test: | ||||
|     sdk: flutter | ||||
|   flutter_test: { sdk: flutter } | ||||
|   bloc_test: ^9.1.0 | ||||
| 
 | ||||
|   wyatt_analysis: | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user