From e76857f1186a29c6ce91148607eecc10081a43a7 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Tue, 2 May 2023 13:32:52 +0200 Subject: [PATCH] feat(layout)!: update layout plugins with new components system --- .../lib/components/custom_app_bar.g.dart | 1 + .../lib/components/custom_bottom_bar.g.dart | 4 ++- .../lib/components/custom_error_widget.dart | 7 ++--- .../lib/components/custom_error_widget.g.dart | 22 ++++++++++---- .../lib/components/custom_loading_widget.dart | 11 ++++--- .../components/custom_loading_widget.g.dart | 29 +++++++++++++++---- .../lib/components/theme_components.dart | 14 ++++----- .../wyatt_bloc_layout/example/lib/main.dart | 6 ++-- .../crud_cubit_consumer_screen_mixin.dart | 7 +++-- .../example/lib/core/app_theme_component.dart | 2 +- .../wyatt_ui_layout/example/lib/main.dart | 2 +- .../lib/pages/app_bar_layout_page.dart | 3 +- .../structural_layouts/frame_layout.dart | 8 ++--- .../top_app_bar_layout.dart | 5 ++-- 14 files changed, 79 insertions(+), 42 deletions(-) diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_app_bar.g.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_app_bar.g.dart index ca934616..bbe73b13 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_app_bar.g.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_app_bar.g.dart @@ -88,6 +88,7 @@ class $CustomAppBarCWProxyImpl implements $TopAppBarComponentCWProxy { Key? key, }) => CustomAppBar( + key: key ?? _value.key, title: title ?? _value.title, ); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_bottom_bar.g.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_bottom_bar.g.dart index 68648c38..463d310f 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_bottom_bar.g.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_bottom_bar.g.dart @@ -24,7 +24,9 @@ class $CustomBottomBarCWProxyImpl int? currentIndex, Key? key, }) => - CustomBottomBar(); + CustomBottomBar( + key: key ?? _value.key, + ); } mixin $CustomBottomBarCWMixin on Component { diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.dart index bbd5ee99..40952513 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.dart @@ -5,13 +5,12 @@ import 'package:wyatt_ui_components/wyatt_ui_components.dart'; part 'custom_error_widget.g.dart'; @ComponentCopyWithExtension() -class CustomErrorWidget extends ErrorWidgetComponent - with $CustomErrorWidgetCWMixin { - CustomErrorWidget({super.key, super.error}); +class CustomErrorWidget extends ErrorComponent with $CustomErrorWidgetCWMixin { + const CustomErrorWidget({super.key, super.details}); @override Widget build(BuildContext context) => ColoredBox( color: Colors.red, - child: Center(child: Text(error?.data ?? 'Error')), + child: Center(child: Text(details?.data ?? 'Error')), ); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.g.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.g.dart index 64db5487..16a49808 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.g.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.g.dart @@ -6,24 +6,36 @@ part of 'custom_error_widget.dart'; // ComponentCopyWithGenerator // ************************************************************************** -class $CustomErrorWidgetCWProxyImpl implements $ErrorWidgetComponentCWProxy { +class $CustomErrorWidgetCWProxyImpl implements $ErrorComponentCWProxy { const $CustomErrorWidgetCWProxyImpl(this._value); final CustomErrorWidget _value; @override - CustomErrorWidget error(TextWrapper? error) => this(error: error); + CustomErrorWidget colors(MultiColor? colors) => this(colors: colors); + @override + CustomErrorWidget message(TextWrapper? message) => this(message: message); + @override + CustomErrorWidget details(TextWrapper? details) => this(details: details); + @override + CustomErrorWidget themeResolver( + ThemeResolver? themeResolver) => + this(themeResolver: themeResolver); @override CustomErrorWidget key(Key? key) => this(key: key); @override CustomErrorWidget call({ - TextWrapper? error, + MultiColor? colors, + TextWrapper? message, + TextWrapper? details, + ThemeResolver? themeResolver, Key? key, }) => CustomErrorWidget( - error: error ?? _value.error, + key: key ?? _value.key, + details: details ?? _value.details, ); } mixin $CustomErrorWidgetCWMixin on Component { - $ErrorWidgetComponentCWProxy get copyWith => + $ErrorComponentCWProxy get copyWith => $CustomErrorWidgetCWProxyImpl(this as CustomErrorWidget); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.dart index bfc75ab2..c996a351 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.dart @@ -5,11 +5,14 @@ import 'package:wyatt_ui_components/wyatt_ui_components.dart'; part 'custom_loading_widget.g.dart'; @ComponentCopyWithExtension() -class CustomLoadingWidget extends LoadingWidgetComponent +class CustomLoadingWidget extends LoaderComponent with $CustomLoadingWidgetCWMixin { - CustomLoadingWidget({super.key, super.color}); + const CustomLoadingWidget({super.key, super.colors}); @override - Widget build(BuildContext context) => - Center(child: CircularProgressIndicator(color: color)); + Widget build(BuildContext context) => Center( + child: CircularProgressIndicator( + color: (colors?.isColor ?? false) ? colors!.color : Colors.blue, + ), + ); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.g.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.g.dart index 55a2ecb3..dfb8ace2 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.g.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.g.dart @@ -6,25 +6,42 @@ part of 'custom_loading_widget.dart'; // ComponentCopyWithGenerator // ************************************************************************** -class $CustomLoadingWidgetCWProxyImpl - implements $LoadingWidgetComponentCWProxy { +class $CustomLoadingWidgetCWProxyImpl implements $LoaderComponentCWProxy { const $CustomLoadingWidgetCWProxyImpl(this._value); final CustomLoadingWidget _value; @override - CustomLoadingWidget color(Color? color) => this(color: color); + CustomLoadingWidget colors(MultiColor? colors) => this(colors: colors); + @override + CustomLoadingWidget radius(double? radius) => this(radius: radius); + @override + CustomLoadingWidget stroke(double? stroke) => this(stroke: stroke); + @override + CustomLoadingWidget duration(Duration? duration) => this(duration: duration); + @override + CustomLoadingWidget flip(bool? flip) => this(flip: flip); + @override + CustomLoadingWidget themeResolver( + ThemeResolver? themeResolver) => + this(themeResolver: themeResolver); @override CustomLoadingWidget key(Key? key) => this(key: key); @override CustomLoadingWidget call({ - Color? color, + MultiColor? colors, + double? radius, + double? stroke, + Duration? duration, + bool? flip, + ThemeResolver? themeResolver, Key? key, }) => CustomLoadingWidget( - color: color ?? _value.color, + key: key ?? _value.key, + colors: colors ?? _value.colors, ); } mixin $CustomLoadingWidgetCWMixin on Component { - $LoadingWidgetComponentCWProxy get copyWith => + $LoaderComponentCWProxy get copyWith => $CustomLoadingWidgetCWProxyImpl(this as CustomLoadingWidget); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/theme_components.dart b/packages/wyatt_bloc_layout/example/lib/components/theme_components.dart index afc4203d..888522dd 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/theme_components.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/theme_components.dart @@ -4,11 +4,11 @@ import 'package:bloc_layout_example/components/custom_error_widget.dart'; import 'package:bloc_layout_example/components/custom_loading_widget.dart'; import 'package:wyatt_ui_components/wyatt_ui_components.dart'; -class AppThemeComponent { - static ComponentThemeData get components => ComponentThemeData.raw( - appBar: const CustomAppBar(), - bottomNavigationBar: const CustomBottomBar(), - loadingWidget: CustomLoadingWidget(), - errorWidget: CustomErrorWidget(), - ); +abstract class AppThemeComponent { + static const ComponentThemeData components = ComponentThemeData.raw( + topAppBar: CustomAppBar(), + bottomNavigationBar: CustomBottomBar(), + loader: CustomLoadingWidget(), + error: CustomErrorWidget(), + ); } diff --git a/packages/wyatt_bloc_layout/example/lib/main.dart b/packages/wyatt_bloc_layout/example/lib/main.dart index 2856aec7..ed7f9709 100644 --- a/packages/wyatt_bloc_layout/example/lib/main.dart +++ b/packages/wyatt_bloc_layout/example/lib/main.dart @@ -32,7 +32,7 @@ class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) => ComponentTheme( - componentThemeWidget: AppThemeComponent.components, + data: AppThemeComponent.components, child: MaterialApp( title: 'Bloc Layout Example', theme: ThemeData( @@ -122,7 +122,7 @@ class ExampleFrameLayoutCrudConsumer ExampleFrameLayoutCrudConsumer({super.key}) : super( customAppBar: (bar) => bar?.copyWith.title( - 'Example Title'.wrap(), + const TextWrapper('Example Title'), ), ); @@ -139,7 +139,7 @@ class ExampleFrameLayoutCrudListConsumer ExampleFrameLayoutCrudListConsumer({super.key}) : super( customAppBar: (bar) => bar?.copyWith.title( - 'Example Title'.wrap(), + const TextWrapper('Example Title'), ), ); diff --git a/packages/wyatt_bloc_layout/lib/src/core/crud_cubit_consumer_screen_mixin.dart b/packages/wyatt_bloc_layout/lib/src/core/crud_cubit_consumer_screen_mixin.dart index d55782e3..7a083f3c 100644 --- a/packages/wyatt_bloc_layout/lib/src/core/crud_cubit_consumer_screen_mixin.dart +++ b/packages/wyatt_bloc_layout/lib/src/core/crud_cubit_consumer_screen_mixin.dart @@ -23,11 +23,12 @@ import 'package:wyatt_ui_components/wyatt_ui_components.dart'; mixin CrudMixin, SuccessState extends CrudSuccess> { Widget errorBuilder(BuildContext context, CrudError state) => - context.components.errorWidget?.copyWith(error: state.message.wrap()) ?? - const SizedBox.shrink(); + context.components.errorComponent.call( + message: (state.message != null) ? TextWrapper(state.message!) : null, + ); Widget loadingBuilder(BuildContext context, CrudLoading state) => - context.components.loadingWidget ?? const SizedBox.shrink(); + context.components.loader ?? const SizedBox.shrink(); Widget initialBuilder(BuildContext context, CrudInitial state) => const SizedBox.shrink(); diff --git a/packages/wyatt_ui_layout/example/lib/core/app_theme_component.dart b/packages/wyatt_ui_layout/example/lib/core/app_theme_component.dart index 233e8385..3df937d1 100644 --- a/packages/wyatt_ui_layout/example/lib/core/app_theme_component.dart +++ b/packages/wyatt_ui_layout/example/lib/core/app_theme_component.dart @@ -7,7 +7,7 @@ import 'package:wyatt_ui_layout_example/pages/bottom_navigation_bar_layout_page_ class AppThemeComponent { static ComponentThemeData get components => ComponentThemeData.raw( - appBar: const CustomAppBar(), + topAppBar: const CustomAppBar(), bottomNavigationBar: CustomBottomNavigationBar( onTap: (context, index) { switch (index) { diff --git a/packages/wyatt_ui_layout/example/lib/main.dart b/packages/wyatt_ui_layout/example/lib/main.dart index 4b2e250d..f4903e21 100644 --- a/packages/wyatt_ui_layout/example/lib/main.dart +++ b/packages/wyatt_ui_layout/example/lib/main.dart @@ -29,7 +29,7 @@ class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) => ComponentTheme( - componentThemeWidget: AppThemeComponent.components, + data: AppThemeComponent.components, child: MaterialApp( title: 'Wyatt Ui Layout Example', theme: ThemeData( diff --git a/packages/wyatt_ui_layout/example/lib/pages/app_bar_layout_page.dart b/packages/wyatt_ui_layout/example/lib/pages/app_bar_layout_page.dart index fd458af7..4b3177e2 100644 --- a/packages/wyatt_ui_layout/example/lib/pages/app_bar_layout_page.dart +++ b/packages/wyatt_ui_layout/example/lib/pages/app_bar_layout_page.dart @@ -7,7 +7,8 @@ class AppBarLayoutPage extends StatelessWidget { @override Widget build(BuildContext context) => TopAppBarLayout( - custom: (p0) => p0?.copyWith.title('New Title'.wrap()), + custom: (topBar) => + topBar?.copyWith.title(const TextWrapper('New Title')), body: const Center( child: Text( 'Body', diff --git a/packages/wyatt_ui_layout/lib/src/presentation/layouts/structural_layouts/frame_layout.dart b/packages/wyatt_ui_layout/lib/src/presentation/layouts/structural_layouts/frame_layout.dart index 144ef867..1bf0ec38 100644 --- a/packages/wyatt_ui_layout/lib/src/presentation/layouts/structural_layouts/frame_layout.dart +++ b/packages/wyatt_ui_layout/lib/src/presentation/layouts/structural_layouts/frame_layout.dart @@ -52,12 +52,12 @@ class FrameLayout extends StructuralLayout { @override Widget build(BuildContext context) => Scaffold( - appBar: (customAppBar?.call(context.components.appBar) != null || - context.components.appBar != null) + appBar: (customAppBar?.call(context.components.topAppBar) != null || + context.components.topAppBar != null) ? PreferredSize( preferredSize: Size.fromHeight(height), - child: customAppBar?.call(context.components.appBar) ?? - context.components.appBar!, + child: customAppBar?.call(context.components.topAppBar) ?? + context.components.topAppBar!, ) : null, body: body, diff --git a/packages/wyatt_ui_layout/lib/src/presentation/layouts/structural_layouts/top_app_bar_layout.dart b/packages/wyatt_ui_layout/lib/src/presentation/layouts/structural_layouts/top_app_bar_layout.dart index 70f61b1e..d6a104b5 100644 --- a/packages/wyatt_ui_layout/lib/src/presentation/layouts/structural_layouts/top_app_bar_layout.dart +++ b/packages/wyatt_ui_layout/lib/src/presentation/layouts/structural_layouts/top_app_bar_layout.dart @@ -82,7 +82,8 @@ class TopAppBarLayout extends TopBarLayout { }); @override - TopAppBarComponent? child(BuildContext context) => context.components.appBar; + TopAppBarComponent? child(BuildContext context) => + context.components.topAppBar; } /// A concrete implementation of [TopBarLayout] for a navigation bar. @@ -102,5 +103,5 @@ class TopNavigationBarLayout extends TopBarLayout { @override TopNavigationBarComponent? child(BuildContext context) => - context.components.topNavigationBarComponent; + context.components.topNavigationBar; }