fix: make components nullable #221
| @ -59,7 +59,7 @@ abstract class TopBarLayout<T extends TopBarComponent> | |||||||
|   final double height; |   final double height; | ||||||
| 
 | 
 | ||||||
|   /// Returns the top bar component for the given [BuildContext]. |   /// Returns the top bar component for the given [BuildContext]. | ||||||
|   T appBar(BuildContext context, String? barId); |   T? appBar(BuildContext context, String? barId); | ||||||
| 
 | 
 | ||||||
|   /// The [scaffoldFieldsWrapper] is a final variable that serves as a wrapper |   /// The [scaffoldFieldsWrapper] is a final variable that serves as a wrapper | ||||||
|   /// for customizing the scaffold. |   /// for customizing the scaffold. | ||||||
| @ -67,18 +67,21 @@ abstract class TopBarLayout<T extends TopBarComponent> | |||||||
|   /// scaffold functionality. |   /// scaffold functionality. | ||||||
|   final ScaffoldFieldsWrapper? scaffoldFieldsWrapper; |   final ScaffoldFieldsWrapper? scaffoldFieldsWrapper; | ||||||
| 
 | 
 | ||||||
|   @override |   PreferredSize? _buildAppBar(BuildContext context) { | ||||||
|   Widget build(BuildContext context) => Scaffold( |     final topAppBar = | ||||||
|         appBar: (custom?.call( |         custom?.call(appBar(context, barId)) ?? appBar(context, barId); | ||||||
|                   appBar(context, barId), | 
 | ||||||
|                 ) != |     return topAppBar != null | ||||||
|                 null) |  | ||||||
|         ? PreferredSize( |         ? PreferredSize( | ||||||
|             preferredSize: Size.fromHeight(height), |             preferredSize: Size.fromHeight(height), | ||||||
|                 child: custom?.call(appBar(context, barId)) ?? |             child: topAppBar, | ||||||
|                     appBar(context, barId), |  | ||||||
|           ) |           ) | ||||||
|             : null, |         : null; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   Widget build(BuildContext context) => Scaffold( | ||||||
|  |         appBar: _buildAppBar(context), | ||||||
|         body: body, |         body: body, | ||||||
|         floatingActionButtonLocation: |         floatingActionButtonLocation: | ||||||
|             scaffoldFieldsWrapper?.floatingActionButtonLocation, |             scaffoldFieldsWrapper?.floatingActionButtonLocation, | ||||||
| @ -130,9 +133,23 @@ class TopAppBarLayout extends TopBarLayout<TopAppBarComponent> { | |||||||
|     super.key, |     super.key, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|  |   PreferredSize? _buildAppBar(BuildContext context) { | ||||||
|  |     final appBar = custom?.call( | ||||||
|  |           context.components.topAppBarComponentOrNull(barId)?.call(), | ||||||
|  |         ) ?? | ||||||
|  |         context.components.topAppBarComponentOrNull(barId)?.call(); | ||||||
|  | 
 | ||||||
|  |     return appBar != null | ||||||
|  |         ? PreferredSize( | ||||||
|  |             preferredSize: Size.fromHeight(height), | ||||||
|  |             child: appBar, | ||||||
|  |           ) | ||||||
|  |         : null; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   @override |   @override | ||||||
|   TopAppBarComponent appBar(BuildContext context, String? barId) => |   TopAppBarComponent? appBar(BuildContext context, String? barId) => | ||||||
|       context.components.topAppBarComponent(barId).call(); |       context.components.topAppBarComponentOrNull(barId)?.call(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// A concrete implementation of [TopBarLayout] for a navigation bar. | /// A concrete implementation of [TopBarLayout] for a navigation bar. | ||||||
| @ -153,6 +170,6 @@ class TopNavigationBarLayout extends TopBarLayout<TopNavigationBarComponent> { | |||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   @override |   @override | ||||||
|   TopNavigationBarComponent appBar(BuildContext context, String? barId) => |   TopNavigationBarComponent? appBar(BuildContext context, String? barId) => | ||||||
|       context.components.topNavigationBarComponent(barId).call(); |       context.components.topNavigationBarComponentOrNull(barId)?.call(); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user