From 1af9b0b1f1426f1815eff2b2228ab9e74a06873f Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Thu, 16 Feb 2023 10:23:48 +0100 Subject: [PATCH 1/3] refactor(ui_kit): make resolve private and dotter child a widget --- .../dotter_border_child.dart | 49 +++++++++++++++++++ .../file_selection_button_screen.dart | 41 ++++------------ .../flat_button/flat_button_screen.dart | 4 +- .../simple_icon_screen.dart | 4 +- .../symbol_button/symbol_button_screen.dart | 4 +- 5 files changed, 64 insertions(+), 38 deletions(-) create mode 100644 packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/dotter_border_child.dart diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/dotter_border_child.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/dotter_border_child.dart new file mode 100644 index 00000000..bc7f03ae --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/dotter_border_child.dart @@ -0,0 +1,49 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import 'package:dotted_border/dotted_border.dart'; +import 'package:flutter/material.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; + +class DotterBorderChild extends StatelessWidget { + const DotterBorderChild({ + required this.style, + required this.child, + super.key, + }); + + final FileSelectionButtonStyle style; + final Widget child; + + @override + Widget build(BuildContext context) { + if (style.borderColors != null && style.stroke != null) { + return DottedBorder( + padding: EdgeInsets.zero, + dashPattern: const [5, 5], + strokeWidth: style.stroke!, + color: style.borderColors!.color, + borderType: BorderType.RRect, + radius: + style.radius?.resolve(TextDirection.ltr).bottomLeft ?? Radius.zero, + strokeCap: StrokeCap.square, + child: child, + ); + } else { + return child; + } + } +} diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_screen.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_screen.dart index b763751c..8f884b51 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_screen.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_screen.dart @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:dotted_border/dotted_border.dart'; import 'package:flutter/material.dart' hide ButtonStyle; import 'package:flutter/services.dart'; import 'package:gap/gap.dart'; @@ -22,6 +21,7 @@ import 'package:wyatt_bloc_helper/wyatt_bloc_helper.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_kit/src/components/buttons/cubit/button_cubit.dart'; import 'package:wyatt_ui_kit/src/components/buttons/cubit/invalid_button_cubit.dart'; +import 'package:wyatt_ui_kit/src/components/buttons/file_selection_button/dotter_border_child.dart'; import 'package:wyatt_ui_kit/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart'; import 'package:wyatt_ui_kit/src/components/gradients/gradient_text.dart'; import 'package:wyatt_ui_kit/src/core/helpers/linear_gradient_helper.dart'; @@ -65,7 +65,7 @@ class FileSelectionButtonScreen InvalidButtonCubit create(BuildContext context) => InvalidButtonCubit(); /// Negotiate the theme to get a complete style. - FileSelectionButtonStyle resolve(BuildContext context, ButtonState state) { + FileSelectionButtonStyle _resolve(BuildContext context, ButtonState state) { final FileSelectionButtonThemeResolver resolver = themeResolver ?? FileSelectionButtonThemeResolver( computeExtensionValueFn: ( @@ -135,31 +135,9 @@ class FileSelectionButtonScreen return resolver.negotiate(context, extra: state); } - Widget _border( - BuildContext context, - FileSelectionButtonStyle style, - Widget child, - ) { - if (style.borderColors != null && style.stroke != null) { - return DottedBorder( - padding: EdgeInsets.zero, - dashPattern: const [5, 5], - strokeWidth: style.stroke!, - color: style.borderColors!.color, - borderType: BorderType.RRect, - radius: - style.radius?.resolve(TextDirection.ltr).bottomLeft ?? Radius.zero, - strokeCap: StrokeCap.square, - child: child, - ); - } else { - return child; - } - } - @override Widget onBuild(BuildContext context, ButtonState state) { - final style = resolve(context, state); + final style = _resolve(context, state); return Focus( onFocusChange: (hasFocus) => @@ -192,10 +170,9 @@ class FileSelectionButtonScreen onPressed?.call(state.state); bloc(context).onClickUpOut(); }, - child: _border( - context, - style, - DecoratedBox( + child: DotterBorderChild( + style: style, + child: DecoratedBox( decoration: BoxDecoration( color: style.backgroundColors?.color, // if no gradient colors => no default value @@ -221,7 +198,7 @@ class FileSelectionButtonScreen children: [ if (leading != null) ...[ leading ?? const SizedBox.shrink(), - Gap((style.padding?.horizontal ?? 10)/2), + Gap((style.padding?.horizontal ?? 10) / 2), ], Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -237,7 +214,7 @@ class FileSelectionButtonScreen /// buttonStyle.foregroundColor.colors ?? /// null /// - /// More infos in `negociate()` method + /// More infos in `ThemeResolver` class if (title != null) ...[ Text( title!.text, @@ -263,7 +240,7 @@ class FileSelectionButtonScreen /// buttonStyle.foregroundColor.colors ?? /// null /// - /// More infos in `negociate()` method + /// More infos in `ThemeResolver` class if (subTitle != null) ...[ const Gap(5), Text( diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_screen.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_screen.dart index b0803388..178cdb01 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_screen.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_screen.dart @@ -59,7 +59,7 @@ class FlatButtonScreen extends CubitScreen { ButtonCubit create(BuildContext context) => ButtonCubit(); /// Negotiate the theme to get a complete style. - FlatButtonStyle resolve(BuildContext context, ControlState state) { + FlatButtonStyle _resolve(BuildContext context, ControlState state) { final FlatButtonThemeResolver resolver = themeResolver ?? FlatButtonThemeResolver( computeExtensionValueFn: ( @@ -103,7 +103,7 @@ class FlatButtonScreen extends CubitScreen { @override Widget onBuild(BuildContext context, ButtonState state) { - final style = resolve(context, state.state); + final style = _resolve(context, state.state); return Focus( onFocusChange: (hasFocus) => diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/simple_icon_button/simple_icon_screen.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/simple_icon_button/simple_icon_screen.dart index 13ea6b8b..7a38de18 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/simple_icon_button/simple_icon_screen.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/simple_icon_button/simple_icon_screen.dart @@ -52,7 +52,7 @@ class SimpleIconButtonScreen extends CubitScreen { ButtonCubit create(BuildContext context) => ButtonCubit(); /// Negotiate the theme to get a complete style. - SimpleIconButtonStyle resolve(BuildContext context, ControlState state) { + SimpleIconButtonStyle _resolve(BuildContext context, ControlState state) { final SimpleIconButtonThemeResolver resolver = themeResolver ?? SimpleIconButtonThemeResolver( computeExtensionValueFn: ( @@ -96,7 +96,7 @@ class SimpleIconButtonScreen extends CubitScreen { @override Widget onBuild(BuildContext context, ButtonState state) { - final style = resolve(context, state.state); + final style = _resolve(context, state.state); return Focus( onFocusChange: (hasFocus) => diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_screen.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_screen.dart index 2491b496..547ebf64 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_screen.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_screen.dart @@ -61,7 +61,7 @@ class SymbolButtonScreen SelectableButtonCubit create(BuildContext context) => SelectableButtonCubit(); /// Negotiate the theme to get a complete style. - SymbolButtonStyle resolve(BuildContext context, ButtonState state) { + SymbolButtonStyle _resolve(BuildContext context, ButtonState state) { final SymbolButtonThemeResolver resolver = themeResolver ?? SymbolButtonThemeResolver( computeExtensionValueFn: ( @@ -127,7 +127,7 @@ class SymbolButtonScreen @override Widget onBuild(BuildContext context, ButtonState state) { - final style = resolve(context, state); + final style = _resolve(context, state); return Focus( onFocusChange: (hasFocus) => -- 2.47.2 From 8044d07413cd9526c5ac5e6dcecc40feb95328e0 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Thu, 16 Feb 2023 11:54:42 +0100 Subject: [PATCH 2/3] fix(ui_component): add style merge in Theme Resolver --- .../lib/src/core/utils/theme_resolver.dart | 14 +++++--- .../entities/buttons/button_component.dart | 5 +-- .../domain/entities/buttons/button_style.dart | 3 +- .../buttons/file_selection_button_style.dart | 36 +++++++++++++++++++ .../entities/buttons/flat_button_style.dart | 32 +++++++++++++++-- .../buttons/simple_icon_button_style.dart | 32 +++++++++++++++++ .../entities/buttons/symbol_button_style.dart | 33 +++++++++++++++++ .../lib/src/domain/entities/component.dart | 6 +++- .../lib/src/domain/entities/entities.dart | 1 + .../lib/src/domain/entities/theme_style.dart | 25 +++++++++++++ 10 files changed, 175 insertions(+), 12 deletions(-) create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/theme_style.dart diff --git a/packages/wyatt_ui_components/lib/src/core/utils/theme_resolver.dart b/packages/wyatt_ui_components/lib/src/core/utils/theme_resolver.dart index cc14f747..45834ca5 100644 --- a/packages/wyatt_ui_components/lib/src/core/utils/theme_resolver.dart +++ b/packages/wyatt_ui_components/lib/src/core/utils/theme_resolver.dart @@ -15,6 +15,7 @@ // along with this program. If not, see . import 'package:flutter/material.dart'; +import 'package:wyatt_ui_components/src/domain/entities/theme_style.dart'; /// {@template theme_resolver} /// In charge of theme negotiation and merge. @@ -30,7 +31,7 @@ import 'package:flutter/material.dart'; /// - If the value is mandatory: a hardcoded value in "wyatt_ui_kit" is chosen. /// - If not, the style is simply not applied. /// {@endtemplate} -abstract class ThemeResolver { +abstract class ThemeResolver, T, E> { /// {@macro theme_resolver} const ThemeResolver(); @@ -81,8 +82,13 @@ abstract class ThemeResolver { /// Choose most suitable style for a given context. S negotiate(BuildContext context, {E? extra}) { S style = computeDefaultValue(context, extra: extra); - style = computeExtensionValue(context, style, extra: extra) ?? style; - style = computeCustomValue(context, style, extra: extra) ?? style; - return style; + final S? extensionStyle = + computeExtensionValue(context, style, extra: extra); + + style = style.mergeWith(extensionStyle); + + final S? customStyle = computeCustomValue(context, style, extra: extra); + + return style.mergeWith(customStyle); } } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_component.dart index a5c285d5..57b543c2 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_component.dart @@ -26,7 +26,7 @@ abstract class ButtonComponent extends Component { this.selectedStyle, this.invalidStyle, this.onPressed, - this.themeResolver, + super.themeResolver, super.key, }); @@ -53,7 +53,4 @@ abstract class ButtonComponent extends Component { /// Callback on button press final void Function(ControlState state)? onPressed; - - /// Theme Resolver for this component - final ThemeResolver? themeResolver; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_style.dart index de126460..9d3fddf9 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_style.dart @@ -16,8 +16,9 @@ import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; +import 'package:wyatt_ui_components/src/domain/entities/theme_style.dart'; -abstract class ButtonStyle { +abstract class ButtonStyle extends ThemeStyle { const ButtonStyle({ this.radius, this.padding, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.dart index e543229b..4bf83810 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.dart @@ -37,6 +37,31 @@ class FileSelectionButtonStyle extends ButtonStyle { super.shadow, }); + /// Merges non-null `b` attributes in `a` + static FileSelectionButtonStyle? merge( + FileSelectionButtonStyle? a, + FileSelectionButtonStyle? b, + ) { + if (b == null) { + return a?.copyWith(); + } + if (a == null) { + return b.copyWith(); + } + + return a.copyWith( + title: b.title, + subTitle: b.subTitle, + radius: b.radius, + padding: b.padding, + foregroundColors: b.foregroundColors, + backgroundColors: b.backgroundColors, + borderColors: b.borderColors, + stroke: b.stroke, + shadow: b.shadow, + ); + } + /// Used for interpolation. static FileSelectionButtonStyle? lerp( FileSelectionButtonStyle? a, @@ -81,4 +106,15 @@ class FileSelectionButtonStyle extends ButtonStyle { /// /// Default to `TextTheme.labelSmall` final TextStyle? subTitle; + + @override + FileSelectionButtonStyle mergeWith(FileSelectionButtonStyle? other) => + FileSelectionButtonStyle.merge(this, other)!; + + @override + FileSelectionButtonStyle? lerpWith( + FileSelectionButtonStyle? other, + double t, + ) => + FileSelectionButtonStyle.lerp(this, other, t); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.dart index cc57472b..980b83d7 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.dart @@ -36,6 +36,30 @@ class FlatButtonStyle extends ButtonStyle { super.shadow, }); + /// Merges non-null `b` attributes in `a` + static FlatButtonStyle? merge( + FlatButtonStyle? a, + FlatButtonStyle? b, + ) { + if (b == null) { + return a?.copyWith(); + } + if (a == null) { + return b.copyWith(); + } + + return a.copyWith( + label: b.label, + radius: b.radius, + padding: b.padding, + foregroundColors: b.foregroundColors, + backgroundColors: b.backgroundColors, + borderColors: b.borderColors, + stroke: b.stroke, + shadow: b.shadow, + ); + } + /// Used for interpolation. static FlatButtonStyle? lerp( FlatButtonStyle? a, @@ -76,6 +100,10 @@ class FlatButtonStyle extends ButtonStyle { final TextStyle? label; @override - String toString() => - 'FlatButtonStyle(label: $label), inherited: ${super.toString()}'; + FlatButtonStyle mergeWith(FlatButtonStyle? other) => + FlatButtonStyle.merge(this, other)!; + + @override + FlatButtonStyle? lerpWith(FlatButtonStyle? other, double t) => + FlatButtonStyle.lerp(this, other, t); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.dart index 3d468e63..70be77bc 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.dart @@ -36,6 +36,30 @@ class SimpleIconButtonStyle extends ButtonStyle { super.shadow, }); + /// Merges non-null `b` attributes in `a` + static SimpleIconButtonStyle? merge( + SimpleIconButtonStyle? a, + SimpleIconButtonStyle? b, + ) { + if (b == null) { + return a?.copyWith(); + } + if (a == null) { + return b.copyWith(); + } + + return a.copyWith( + dimension: b.dimension, + radius: b.radius, + padding: b.padding, + foregroundColors: b.foregroundColors, + backgroundColors: b.backgroundColors, + borderColors: b.borderColors, + stroke: b.stroke, + shadow: b.shadow, + ); + } + /// Used for interpolation. static SimpleIconButtonStyle? lerp( SimpleIconButtonStyle? a, @@ -74,4 +98,12 @@ class SimpleIconButtonStyle extends ButtonStyle { /// /// Default to `context.buttonTheme.height` final double? dimension; + + @override + SimpleIconButtonStyle mergeWith(SimpleIconButtonStyle? other) => + SimpleIconButtonStyle.merge(this, other)!; + + @override + SimpleIconButtonStyle? lerpWith(SimpleIconButtonStyle? other, double t) => + SimpleIconButtonStyle.lerp(this, other, t); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.dart index ab5c44b8..7f8e7b6d 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.dart @@ -37,6 +37,31 @@ class SymbolButtonStyle extends ButtonStyle { super.shadow, }); + /// Merges non-null `b` attributes in `a` + static SymbolButtonStyle? merge( + SymbolButtonStyle? a, + SymbolButtonStyle? b, + ) { + if (b == null) { + return a?.copyWith(); + } + if (a == null) { + return b.copyWith(); + } + + return a.copyWith( + label: b.label, + dimension: b.dimension, + radius: b.radius, + padding: b.padding, + foregroundColors: b.foregroundColors, + backgroundColors: b.backgroundColors, + borderColors: b.borderColors, + stroke: b.stroke, + shadow: b.shadow, + ); + } + /// Used for interpolation. static SymbolButtonStyle? lerp( SymbolButtonStyle? a, @@ -81,4 +106,12 @@ class SymbolButtonStyle extends ButtonStyle { /// /// Default to `context.buttonTheme.height` final double? dimension; + + @override + SymbolButtonStyle mergeWith(SymbolButtonStyle? other) => + SymbolButtonStyle.merge(this, other)!; + + @override + SymbolButtonStyle? lerpWith(SymbolButtonStyle? other, double t) => + SymbolButtonStyle.lerp(this, other, t); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/component.dart index 33f05fbd..e7f984f1 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/component.dart @@ -15,7 +15,11 @@ // along with this program. If not, see . import 'package:flutter/material.dart'; +import 'package:wyatt_ui_components/src/core/utils/theme_resolver.dart'; abstract class Component extends StatelessWidget { - const Component({super.key}); + const Component({this.themeResolver, super.key}); + + /// Theme Resolver for this component + final ThemeResolver? themeResolver; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart b/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart index 5a07411a..39ae2f65 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart @@ -21,3 +21,4 @@ export './cards/cards.dart'; export './component.dart'; export './error_widget_component.dart'; export './loading_widget_component.dart'; +export './theme_style.dart'; diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/theme_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/theme_style.dart new file mode 100644 index 00000000..7c923ac0 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/theme_style.dart @@ -0,0 +1,25 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +abstract class ThemeStyle { + const ThemeStyle(); + + /// Merges non-null `other` attributes in `this` and returns a copy. + T mergeWith(T? other); + + /// Used for interpolation. + T? lerpWith(T? other, double t); +} -- 2.47.2 From 4c08a692d2013a0732e0bacbe70c88db78eb2d98 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Thu, 16 Feb 2023 11:55:11 +0100 Subject: [PATCH 3/3] refactor(ui_kit): move exportable bloc from mixin to widget --- .../buttons/exportable_bloc.dart} | 18 ++++++++++++++---- .../file_selection_button.dart | 8 ++++---- .../buttons/flat_button/flat_button.dart | 9 ++++----- .../simple_icon_button/simple_icon_button.dart | 8 ++++---- .../buttons/symbol_button/symbol_button.dart | 8 ++++---- 5 files changed, 30 insertions(+), 21 deletions(-) rename packages/wyatt_ui_kit/lib/src/{core/mixin/export_bloc_mixin.dart => components/buttons/exportable_bloc.dart} (70%) diff --git a/packages/wyatt_ui_kit/lib/src/core/mixin/export_bloc_mixin.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/exportable_bloc.dart similarity index 70% rename from packages/wyatt_ui_kit/lib/src/core/mixin/export_bloc_mixin.dart rename to packages/wyatt_ui_kit/lib/src/components/buttons/exportable_bloc.dart index f2ae41bf..0f9fbd73 100644 --- a/packages/wyatt_ui_kit/lib/src/core/mixin/export_bloc_mixin.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/exportable_bloc.dart @@ -14,12 +14,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:flutter/widgets.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -mixin ExportBloc> { - T get bloc; - Widget exportBloc({required Widget child}) => BlocProvider.value( +class ExportableBloc> + extends StatelessWidget { + const ExportableBloc({ + required this.bloc, + required this.child, + super.key, + }); + + final T bloc; + final Widget child; + + @override + Widget build(BuildContext context) => BlocProvider.value( value: bloc, child: child, ); diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button.dart index aeebaa43..1c038237 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button.dart @@ -18,15 +18,15 @@ import 'package:flutter/material.dart' hide ButtonStyle; import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_kit/src/components/buttons/cubit/invalid_button_cubit.dart'; +import 'package:wyatt_ui_kit/src/components/buttons/exportable_bloc.dart'; import 'package:wyatt_ui_kit/src/components/buttons/file_selection_button/file_selection_button_screen.dart'; import 'package:wyatt_ui_kit/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart'; -import 'package:wyatt_ui_kit/src/core/mixin/export_bloc_mixin.dart'; part 'file_selection_button.g.dart'; @ComponentCopyWithExtension() class FileSelectionButton extends FileSelectionButtonComponent - with $FileSelectionButtonCWMixin, ExportBloc { + with $FileSelectionButtonCWMixin { FileSelectionButton({ super.leading, super.title, @@ -46,7 +46,6 @@ class FileSelectionButton extends FileSelectionButtonComponent final InvalidButtonCubit _cubit = InvalidButtonCubit(); - @override InvalidButtonCubit get bloc => _cubit; @override @@ -82,7 +81,8 @@ class FileSelectionButton extends FileSelectionButtonComponent super.themeResolver as FileSelectionButtonThemeResolver?; @override - Widget build(BuildContext context) => exportBloc( + Widget build(BuildContext context) => ExportableBloc( + bloc: _cubit, child: FileSelectionButtonScreen( leading: leading, title: title, diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button.dart index 123b91c2..df67bb11 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button.dart @@ -18,15 +18,14 @@ import 'package:flutter/material.dart' hide ButtonStyle; import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_kit/src/components/buttons/cubit/button_cubit.dart'; +import 'package:wyatt_ui_kit/src/components/buttons/exportable_bloc.dart'; import 'package:wyatt_ui_kit/src/components/buttons/flat_button/flat_button_screen.dart'; import 'package:wyatt_ui_kit/src/components/buttons/flat_button/flat_button_theme_resolver.dart'; -import 'package:wyatt_ui_kit/src/core/mixin/export_bloc_mixin.dart'; part 'flat_button.g.dart'; @ComponentCopyWithExtension() -class FlatButton extends FlatButtonComponent - with $FlatButtonCWMixin, ExportBloc { +class FlatButton extends FlatButtonComponent with $FlatButtonCWMixin { FlatButton({ super.prefix, super.suffix, @@ -44,7 +43,6 @@ class FlatButton extends FlatButtonComponent final ButtonCubit _cubit = ButtonCubit(); - @override ButtonCubit get bloc => _cubit; @override @@ -67,7 +65,8 @@ class FlatButton extends FlatButtonComponent super.themeResolver as FlatButtonThemeResolver?; @override - Widget build(BuildContext context) => exportBloc( + Widget build(BuildContext context) => ExportableBloc( + bloc: _cubit, child: FlatButtonScreen( prefix: prefix, suffix: suffix, diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/simple_icon_button/simple_icon_button.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/simple_icon_button/simple_icon_button.dart index 0322265a..9bd074b1 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/simple_icon_button/simple_icon_button.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/simple_icon_button/simple_icon_button.dart @@ -18,15 +18,15 @@ import 'package:flutter/material.dart' hide ButtonStyle; import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_kit/src/components/buttons/cubit/button_cubit.dart'; +import 'package:wyatt_ui_kit/src/components/buttons/exportable_bloc.dart'; import 'package:wyatt_ui_kit/src/components/buttons/simple_icon_button/simple_icon_button_theme_resolver.dart'; import 'package:wyatt_ui_kit/src/components/buttons/simple_icon_button/simple_icon_screen.dart'; -import 'package:wyatt_ui_kit/src/core/mixin/export_bloc_mixin.dart'; part 'simple_icon_button.g.dart'; @ComponentCopyWithExtension() class SimpleIconButton extends SimpleIconButtonComponent - with $SimpleIconButtonCWMixin, ExportBloc { + with $SimpleIconButtonCWMixin { SimpleIconButton({ super.icon, super.disabledStyle, @@ -41,7 +41,6 @@ class SimpleIconButton extends SimpleIconButtonComponent final ButtonCubit _cubit = ButtonCubit(); - @override ButtonCubit get bloc => _cubit; @override @@ -69,7 +68,8 @@ class SimpleIconButton extends SimpleIconButtonComponent super.themeResolver as SimpleIconButtonThemeResolver?; @override - Widget build(BuildContext context) => exportBloc( + Widget build(BuildContext context) => ExportableBloc( + bloc: _cubit, child: SimpleIconButtonScreen( icon: icon, disabledStyle: disabledStyle, diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button.dart index 1a328042..64436fa5 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button.dart @@ -18,15 +18,15 @@ import 'package:flutter/material.dart' hide ButtonStyle; import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_kit/src/components/buttons/cubit/selectable_button_cubit.dart'; +import 'package:wyatt_ui_kit/src/components/buttons/exportable_bloc.dart'; import 'package:wyatt_ui_kit/src/components/buttons/symbol_button/symbol_button_screen.dart'; import 'package:wyatt_ui_kit/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart'; -import 'package:wyatt_ui_kit/src/core/mixin/export_bloc_mixin.dart'; part 'symbol_button.g.dart'; @ComponentCopyWithExtension() class SymbolButton extends SymbolButtonComponent - with $SymbolButtonCWMixin, ExportBloc { + with $SymbolButtonCWMixin{ SymbolButton({ super.icon, super.label, @@ -44,7 +44,6 @@ class SymbolButton extends SymbolButtonComponent final SelectableButtonCubit _cubit = SelectableButtonCubit(); - @override SelectableButtonCubit get bloc => _cubit; @override @@ -74,7 +73,8 @@ class SymbolButton extends SymbolButtonComponent super.themeResolver as SymbolButtonThemeResolver?; @override - Widget build(BuildContext context) => exportBloc( + Widget build(BuildContext context) => ExportableBloc( + bloc: _cubit, child: SymbolButtonScreen( icon: icon, label: label, -- 2.47.2