From 419c99c10345657c46fd9cafa3e35e5c0d62c725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Thu, 16 Feb 2023 10:16:57 +0100 Subject: [PATCH 01/25] feat(ui_components): add text input abstract class (#138) --- .../domain/entities/text_input_component.dart | 151 ++++++++++++++++++ .../entities/text_input_component.g.dart | 139 ++++++++++++++++ 2 files changed, 290 insertions(+) create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart new file mode 100644 index 00000000..fc7a78dc --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart @@ -0,0 +1,151 @@ +// 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 'dart:ui'; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; + +part 'text_input_component.g.dart'; + +@ComponentProxyExtension() +abstract class TextInputComponent extends Component + with CopyWithMixin<$TextInputComponentCWProxy> { + const TextInputComponent({ + this.backgroundColors, + this.borderColors, + this.radius, + this.controller, + this.focusNode, + this.decoration, + this.keyboardType, + this.smartDashesType, + this.smartQuotesType, + this.enableInteractiveSelection, + this.textInputAction, + this.textCapitalization, + this.style, + this.strutStyle, + this.textAlign, + this.textAlignVertical, + this.textDirection, + this.readOnly, + this.showCursor, + this.autofocus, + this.obscuringCharacter, + this.obscureText, + this.autocorrect, + this.enableSuggestions, + this.maxLines, + this.minLines, + this.expands, + this.maxLength, + this.maxLengthEnforcement, + this.onChanged, + this.onEditingComplete, + this.onSubmitted, + this.onAppPrivateCommand, + this.inputFormatters, + this.enabled, + this.cursorWidth, + this.cursorHeight, + this.cursorRadius, + this.cursorColor, + this.selectionHeightStyle, + this.selectionWidthStyle, + this.keyboardAppearance, + this.scrollPadding, + this.dragStartBehavior, + this.selectionControls, + this.onTap, + this.onTapOutside, + this.mouseCursor, + this.scrollController, + this.scrollPhysics, + this.autofillHints, + this.clipBehavior, + this.restorationId, + this.scribbleEnabled, + this.enableIMEPersonalizedLearning, + this.contextMenuBuilder, + this.spellCheckConfiguration, + this.magnifierConfiguration, + super.key, + }); + + final TextMagnifierConfiguration? magnifierConfiguration; + final TextEditingController? controller; + final FocusNode? focusNode; + final InputDecoration? decoration; + final TextInputType? keyboardType; + final TextInputAction? textInputAction; + final TextCapitalization? textCapitalization; + final TextStyle? style; + final StrutStyle? strutStyle; + final TextAlign? textAlign; + final TextAlignVertical? textAlignVertical; + final TextDirection? textDirection; + final bool? autofocus; + final String? obscuringCharacter; + final bool? obscureText; + final bool? autocorrect; + final SmartDashesType? smartDashesType; + final SmartQuotesType? smartQuotesType; + final bool? enableSuggestions; + final int? maxLines; + final int? minLines; + final bool? expands; + final bool? readOnly; + final bool? showCursor; + final int? maxLength; + final MaxLengthEnforcement? maxLengthEnforcement; + final ValueChanged? onChanged; + final VoidCallback? onEditingComplete; + final ValueChanged? onSubmitted; + final AppPrivateCommandCallback? onAppPrivateCommand; + final List? inputFormatters; + final bool? enabled; + final double? cursorWidth; + final double? cursorHeight; + final Radius? cursorRadius; + final Color? cursorColor; + final BoxHeightStyle? selectionHeightStyle; + final BoxWidthStyle? selectionWidthStyle; + final Brightness? keyboardAppearance; + final EdgeInsets? scrollPadding; + final bool? enableInteractiveSelection; + final TextSelectionControls? selectionControls; + final DragStartBehavior? dragStartBehavior; + final GestureTapCallback? onTap; + final TapRegionCallback? onTapOutside; + final MouseCursor? mouseCursor; + final ScrollPhysics? scrollPhysics; + final ScrollController? scrollController; + final Iterable? autofillHints; + final Clip? clipBehavior; + final String? restorationId; + final bool? scribbleEnabled; + final bool? enableIMEPersonalizedLearning; + final EditableTextContextMenuBuilder? contextMenuBuilder; + final SpellCheckConfiguration? spellCheckConfiguration; + + final List? backgroundColors; + final List? borderColors; + final double? radius; +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart new file mode 100644 index 00000000..da0342ae --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart @@ -0,0 +1,139 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'text_input_component.dart'; + +// ************************************************************************** +// ComponentProxyGenerator +// ************************************************************************** + +abstract class $TextInputComponentCWProxy { + TextInputComponent backgroundColors(List? backgroundColors); + TextInputComponent borderColors(List? borderColors); + TextInputComponent radius(double? radius); + TextInputComponent controller(TextEditingController? controller); + TextInputComponent focusNode(FocusNode? focusNode); + TextInputComponent decoration(InputDecoration? decoration); + TextInputComponent keyboardType(TextInputType? keyboardType); + TextInputComponent smartDashesType(SmartDashesType? smartDashesType); + TextInputComponent smartQuotesType(SmartQuotesType? smartQuotesType); + TextInputComponent enableInteractiveSelection( + bool? enableInteractiveSelection); + TextInputComponent textInputAction(TextInputAction? textInputAction); + TextInputComponent textCapitalization(TextCapitalization? textCapitalization); + TextInputComponent style(TextStyle? style); + TextInputComponent strutStyle(StrutStyle? strutStyle); + TextInputComponent textAlign(TextAlign? textAlign); + TextInputComponent textAlignVertical(TextAlignVertical? textAlignVertical); + TextInputComponent textDirection(TextDirection? textDirection); + TextInputComponent readOnly(bool? readOnly); + TextInputComponent showCursor(bool? showCursor); + TextInputComponent autofocus(bool? autofocus); + TextInputComponent obscuringCharacter(String? obscuringCharacter); + TextInputComponent obscureText(bool? obscureText); + TextInputComponent autocorrect(bool? autocorrect); + TextInputComponent enableSuggestions(bool? enableSuggestions); + TextInputComponent maxLines(int? maxLines); + TextInputComponent minLines(int? minLines); + TextInputComponent expands(bool? expands); + TextInputComponent maxLength(int? maxLength); + TextInputComponent maxLengthEnforcement( + MaxLengthEnforcement? maxLengthEnforcement); + TextInputComponent onChanged(void Function(String)? onChanged); + TextInputComponent onEditingComplete(void Function()? onEditingComplete); + TextInputComponent onSubmitted(void Function(String)? onSubmitted); + TextInputComponent onAppPrivateCommand( + void Function(String, Map)? onAppPrivateCommand); + TextInputComponent inputFormatters(List? inputFormatters); + TextInputComponent enabled(bool? enabled); + TextInputComponent cursorWidth(double? cursorWidth); + TextInputComponent cursorHeight(double? cursorHeight); + TextInputComponent cursorRadius(Radius? cursorRadius); + TextInputComponent cursorColor(Color? cursorColor); + TextInputComponent selectionHeightStyle(BoxHeightStyle? selectionHeightStyle); + TextInputComponent selectionWidthStyle(BoxWidthStyle? selectionWidthStyle); + TextInputComponent keyboardAppearance(Brightness? keyboardAppearance); + TextInputComponent scrollPadding(EdgeInsets? scrollPadding); + TextInputComponent dragStartBehavior(DragStartBehavior? dragStartBehavior); + TextInputComponent selectionControls( + TextSelectionControls? selectionControls); + TextInputComponent onTap(void Function()? onTap); + TextInputComponent onTapOutside( + void Function(PointerDownEvent)? onTapOutside); + TextInputComponent mouseCursor(MouseCursor? mouseCursor); + TextInputComponent scrollController(ScrollController? scrollController); + TextInputComponent scrollPhysics(ScrollPhysics? scrollPhysics); + TextInputComponent autofillHints(Iterable? autofillHints); + TextInputComponent clipBehavior(Clip? clipBehavior); + TextInputComponent restorationId(String? restorationId); + TextInputComponent scribbleEnabled(bool? scribbleEnabled); + TextInputComponent enableIMEPersonalizedLearning( + bool? enableIMEPersonalizedLearning); + TextInputComponent contextMenuBuilder( + Widget Function(BuildContext, EditableTextState)? contextMenuBuilder); + TextInputComponent spellCheckConfiguration( + SpellCheckConfiguration? spellCheckConfiguration); + TextInputComponent magnifierConfiguration( + TextMagnifierConfiguration? magnifierConfiguration); + TextInputComponent key(Key? key); + TextInputComponent call({ + List? backgroundColors, + List? borderColors, + double? radius, + TextEditingController? controller, + FocusNode? focusNode, + InputDecoration? decoration, + TextInputType? keyboardType, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + bool? enableInteractiveSelection, + TextInputAction? textInputAction, + TextCapitalization? textCapitalization, + TextStyle? style, + StrutStyle? strutStyle, + TextAlign? textAlign, + TextAlignVertical? textAlignVertical, + TextDirection? textDirection, + bool? readOnly, + bool? showCursor, + bool? autofocus, + String? obscuringCharacter, + bool? obscureText, + bool? autocorrect, + bool? enableSuggestions, + int? maxLines, + int? minLines, + bool? expands, + int? maxLength, + MaxLengthEnforcement? maxLengthEnforcement, + void Function(String)? onChanged, + void Function()? onEditingComplete, + void Function(String)? onSubmitted, + void Function(String, Map)? onAppPrivateCommand, + List? inputFormatters, + bool? enabled, + double? cursorWidth, + double? cursorHeight, + Radius? cursorRadius, + Color? cursorColor, + BoxHeightStyle? selectionHeightStyle, + BoxWidthStyle? selectionWidthStyle, + Brightness? keyboardAppearance, + EdgeInsets? scrollPadding, + DragStartBehavior? dragStartBehavior, + TextSelectionControls? selectionControls, + void Function()? onTap, + void Function(PointerDownEvent)? onTapOutside, + MouseCursor? mouseCursor, + ScrollController? scrollController, + ScrollPhysics? scrollPhysics, + Iterable? autofillHints, + Clip? clipBehavior, + String? restorationId, + bool? scribbleEnabled, + bool? enableIMEPersonalizedLearning, + Widget Function(BuildContext, EditableTextState)? contextMenuBuilder, + SpellCheckConfiguration? spellCheckConfiguration, + TextMagnifierConfiguration? magnifierConfiguration, + Key? key, + }); +} -- 2.47.2 From 1e8d5d088e8746b1406018afc361599ca618ceea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Thu, 16 Feb 2023 10:23:37 +0100 Subject: [PATCH 02/25] chore(ui_components): export text inputs (#138) --- .../wyatt_ui_components/lib/src/domain/entities/entities.dart | 1 + 1 file changed, 1 insertion(+) 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 85ce40c3..4a9a67a0 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart @@ -24,4 +24,5 @@ export './loader_component.dart'; export './loader_style.dart'; export './loading_widget_component.dart'; export './rich_text_builder/rich_text_builder.dart'; +export './text_input_component.dart'; export './theme_style.dart'; -- 2.47.2 From c2b60f2d7961f5f95489b08c289a7e12822a800d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Thu, 16 Feb 2023 10:26:40 +0100 Subject: [PATCH 03/25] feat(ui_kit): add text input theme extension (#138) --- .../domain/input_text_theme_extension.dart | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/wyatt_ui_kit/lib/src/domain/input_text_theme_extension.dart diff --git a/packages/wyatt_ui_kit/lib/src/domain/input_text_theme_extension.dart b/packages/wyatt_ui_kit/lib/src/domain/input_text_theme_extension.dart new file mode 100644 index 00000000..d71340fc --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/domain/input_text_theme_extension.dart @@ -0,0 +1,36 @@ +// 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:flutter/material.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; + +abstract class InputTexThemetExtension + extends ThemeExtension { + InputTexThemetExtension({ + this.backgroundColors, + this.borderColors, + this.floatingLabelTextStyle, + this.inputStyle, + }); + + // Colors: + final MultiColor? backgroundColors; + final MultiColor? borderColors; + + // TextStyles: + final TextStyle? floatingLabelTextStyle; + final TextStyle? inputStyle; +} -- 2.47.2 From c6beae597bc0957c7782bac9a78b0ffeab293ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Thu, 16 Feb 2023 13:14:01 +0100 Subject: [PATCH 04/25] refactor(ui_components): update colors using Multicolor class (#138) --- .../lib/src/domain/entities/text_input_component.dart | 4 ++-- .../lib/src/domain/entities/text_input_component.g.dart | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart index fc7a78dc..f89985e6 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart @@ -145,7 +145,7 @@ abstract class TextInputComponent extends Component final EditableTextContextMenuBuilder? contextMenuBuilder; final SpellCheckConfiguration? spellCheckConfiguration; - final List? backgroundColors; - final List? borderColors; + final MultiColor? backgroundColors; + final MultiColor? borderColors; final double? radius; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart index da0342ae..0bb149e2 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart @@ -7,8 +7,8 @@ part of 'text_input_component.dart'; // ************************************************************************** abstract class $TextInputComponentCWProxy { - TextInputComponent backgroundColors(List? backgroundColors); - TextInputComponent borderColors(List? borderColors); + TextInputComponent backgroundColors(MultiColor? backgroundColors); + TextInputComponent borderColors(MultiColor? borderColors); TextInputComponent radius(double? radius); TextInputComponent controller(TextEditingController? controller); TextInputComponent focusNode(FocusNode? focusNode); @@ -76,8 +76,8 @@ abstract class $TextInputComponentCWProxy { TextMagnifierConfiguration? magnifierConfiguration); TextInputComponent key(Key? key); TextInputComponent call({ - List? backgroundColors, - List? borderColors, + MultiColor? backgroundColors, + MultiColor? borderColors, double? radius, TextEditingController? controller, FocusNode? focusNode, -- 2.47.2 From f6c16c5dc40375aabe7bfb7f3f1e11a8016e1e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Thu, 16 Feb 2023 13:25:25 +0100 Subject: [PATCH 05/25] feat(ui_components): add isColor getter in multicolor helper --- .../lib/src/core/utils/multi_color.dart | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart b/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart index 8f36e970..aa37be5b 100644 --- a/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart +++ b/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart @@ -23,24 +23,20 @@ class MultiColor { final List? _colors; final Color? _color; - Color get color { - if (_color != null) { - return _color!; - } - if (_colors?.isNotEmpty ?? false) { - return _colors!.first; - } - throw IndexError.withLength( - 0, - _colors?.length ?? 0, - message: '_color is not defined or _colors is empty.', - ); - } + Color get color => _color != null + ? _color! + : _colors?.isNotEmpty ?? false + ? _colors!.first + : throw IndexError.withLength( + 0, + _colors?.length ?? 0, + message: '_color is not defined or _colors is empty.', + ); List get colors => _colors ?? []; - bool get isGradient => - (_colors?.isNotEmpty ?? false) && (_colors?.length ?? 0) > 1; + bool get isGradient => (_colors?.length ?? 0) > 1; + bool get isColor => _color != null || isGradient; static MultiColor? lerp(MultiColor? a, MultiColor? b, double t) { if (a == null && b == null) { -- 2.47.2 From edf72cf4c2a235d9383470bfa04b222fe5603c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 08:20:37 +0100 Subject: [PATCH 06/25] feat(ui_components):add text input components, theme extension and worked on utils (#138) --- .../lib/src/core/core.dart | 2 +- .../lib/src/core/enums/enums.dart | 18 ++ .../lib/src/core/enums/status_state.dart | 22 +++ .../lib/src/core/utils/multi_color.dart | 30 ++- .../lib/src/core/utils/theme_resolver.dart | 41 ++-- .../lib/src/domain/entities/entities.dart | 2 +- .../text_input_component.dart | 40 +++- .../text_input_component.g.dart | 38 +++- .../text_inputs/text_input_style.dart | 102 ++++++++++ .../text_inputs/text_input_style.g.dart | 185 ++++++++++++++++++ .../entities/text_inputs/text_inputs.dart | 18 ++ 11 files changed, 454 insertions(+), 44 deletions(-) create mode 100644 packages/wyatt_ui_components/lib/src/core/enums/enums.dart create mode 100644 packages/wyatt_ui_components/lib/src/core/enums/status_state.dart rename packages/wyatt_ui_components/lib/src/domain/entities/{ => text_inputs}/text_input_component.dart (86%) rename packages/wyatt_ui_components/lib/src/domain/entities/{ => text_inputs}/text_input_component.g.dart (82%) create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.g.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_inputs.dart diff --git a/packages/wyatt_ui_components/lib/src/core/core.dart b/packages/wyatt_ui_components/lib/src/core/core.dart index a18f1e81..50874264 100644 --- a/packages/wyatt_ui_components/lib/src/core/core.dart +++ b/packages/wyatt_ui_components/lib/src/core/core.dart @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -export 'enums/control_state.dart'; +export 'enums/enums.dart'; export 'extensions/build_context_extensions.dart'; export 'extensions/string_extension.dart'; export 'mixins/copy_with_mixin.dart'; diff --git a/packages/wyatt_ui_components/lib/src/core/enums/enums.dart b/packages/wyatt_ui_components/lib/src/core/enums/enums.dart new file mode 100644 index 00000000..9b4b1438 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/core/enums/enums.dart @@ -0,0 +1,18 @@ +// 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 . + +export './control_state.dart'; +export './status_state.dart'; diff --git a/packages/wyatt_ui_components/lib/src/core/enums/status_state.dart b/packages/wyatt_ui_components/lib/src/core/enums/status_state.dart new file mode 100644 index 00000000..878899f6 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/core/enums/status_state.dart @@ -0,0 +1,22 @@ +// 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 . + +enum StatusState { + initial, + success, + loading, + error; +} diff --git a/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart b/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart index aa37be5b..9e9b7222 100644 --- a/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart +++ b/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart @@ -41,10 +41,36 @@ class MultiColor { static MultiColor? lerp(MultiColor? a, MultiColor? b, double t) { if (a == null && b == null) { return null; - } - if (b == null) { + } else if (a == null) { + return b; + } else if (b == null) { return a; } + if (a.isColor && b.isColor) { + return MultiColor.single(Color.lerp(a.color, b.color, t)); + } else if (a.isColor && b.isGradient) { + return MultiColor( + b.colors + .map((e) => Color.lerp(a.color, e, t)) + .whereType() + .toList(), + ); + } else if (a.isGradient && b.isColor) { + return MultiColor( + a.colors + .map((e) => Color.lerp(b.color, e, t)) + .whereType() + .toList(), + ); + } else if (a.isGradient && b.isGradient) { + final colors = List.empty(growable: true); + for (int i = 0; i < a.colors.length; i++) { + final lerpColor = Color.lerp(a.colors[i], b.colors[i], t); + if (lerpColor != null) { + colors.add(lerpColor); + } + } + } return b; } 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 45834ca5..c77e588b 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 @@ -35,24 +35,26 @@ abstract class ThemeResolver, T, E> { /// {@macro theme_resolver} const ThemeResolver(); - S? Function( - BuildContext context, - S defaultValue, - T themeExtension, { - E? extra, - }) get computeExtensionValueFn; - S? Function(BuildContext context, {E? extra}) get customStyleFn; + S? Function(BuildContext context, S extensionValue, {E? extra}) + get customStyleFn; /// Compute default value from Flutter Theme or with hardcoded values. S computeDefaultValue(BuildContext context, {E? extra}); + S? computeExtensionValueFn( + BuildContext context, + S defaultValue, + T themeExtension, { + E? extra, + }); + /// Compute values from the extension if found - S? computeExtensionValue( + S? _computeExtensionValue( BuildContext context, S defaultValue, { E? extra, }) { - final themeExtension = findExtension(context); + final themeExtension = Theme.of(context).extension(); if (themeExtension != null) { return computeExtensionValueFn( context, @@ -65,30 +67,27 @@ abstract class ThemeResolver, T, E> { } /// Compute custom value - S? computeCustomValue( + S? _computeCustomValue( BuildContext context, S previousPhaseValue, { E? extra, }) { - final customStyle = customStyleFn(context, extra: extra); + final customStyle = customStyleFn( + context, + previousPhaseValue, + extra: extra, + ); if (customStyle != null) { return customStyle; } return previousPhaseValue; } - T? findExtension(BuildContext context) => Theme.of(context).extension(); - /// Choose most suitable style for a given context. S negotiate(BuildContext context, {E? extra}) { S style = computeDefaultValue(context, extra: extra); - final S? extensionStyle = - computeExtensionValue(context, style, extra: extra); - - style = style.mergeWith(extensionStyle); - - final S? customStyle = computeCustomValue(context, style, extra: extra); - - return style.mergeWith(customStyle); + style = _computeExtensionValue(context, style, extra: extra) ?? style; + style = _computeCustomValue(context, style, extra: extra) ?? style; + return style; } } 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 4a9a67a0..93e81e4a 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart @@ -24,5 +24,5 @@ export './loader_component.dart'; export './loader_style.dart'; export './loading_widget_component.dart'; export './rich_text_builder/rich_text_builder.dart'; -export './text_input_component.dart'; +export './text_inputs/text_inputs.dart'; export './theme_style.dart'; diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_component.dart similarity index 86% rename from packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart rename to packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_component.dart index f89985e6..2963da6a 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_component.dart @@ -28,12 +28,21 @@ part 'text_input_component.g.dart'; abstract class TextInputComponent extends Component with CopyWithMixin<$TextInputComponentCWProxy> { const TextInputComponent({ - this.backgroundColors, - this.borderColors, - this.radius, + this.expand, + this.onError, + this.validator, + this.suffixText, + this.prefixText, + this.prefixIcon, + this.suffixIcon, + this.label, + this.hint, + this.normalStyle, + this.focusedStyle, + this.errorStyle, + this.disableStyle, this.controller, this.focusNode, - this.decoration, this.keyboardType, this.smartDashesType, this.smartQuotesType, @@ -92,7 +101,6 @@ abstract class TextInputComponent extends Component final TextMagnifierConfiguration? magnifierConfiguration; final TextEditingController? controller; final FocusNode? focusNode; - final InputDecoration? decoration; final TextInputType? keyboardType; final TextInputAction? textInputAction; final TextCapitalization? textCapitalization; @@ -120,7 +128,7 @@ abstract class TextInputComponent extends Component final ValueChanged? onSubmitted; final AppPrivateCommandCallback? onAppPrivateCommand; final List? inputFormatters; - final bool? enabled; + final ValueNotifier? enabled; final double? cursorWidth; final double? cursorHeight; final Radius? cursorRadius; @@ -145,7 +153,21 @@ abstract class TextInputComponent extends Component final EditableTextContextMenuBuilder? contextMenuBuilder; final SpellCheckConfiguration? spellCheckConfiguration; - final MultiColor? backgroundColors; - final MultiColor? borderColors; - final double? radius; + final bool Function(String)? validator; + final String? Function(String)? onError; + + final TextInputStyle? normalStyle; + final TextInputStyle? focusedStyle; + final TextInputStyle? errorStyle; + final TextInputStyle? disableStyle; + + final bool? expand; + + final TextWrapper? label; + final TextWrapper? hint; + + final TextWrapper? prefixText; + final TextWrapper? suffixText; + final Icon? prefixIcon; + final Icon? suffixIcon; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_component.g.dart similarity index 82% rename from packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart rename to packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_component.g.dart index 0bb149e2..59083bd6 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_input_component.g.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_component.g.dart @@ -7,12 +7,21 @@ part of 'text_input_component.dart'; // ************************************************************************** abstract class $TextInputComponentCWProxy { - TextInputComponent backgroundColors(MultiColor? backgroundColors); - TextInputComponent borderColors(MultiColor? borderColors); - TextInputComponent radius(double? radius); + TextInputComponent expand(bool? expand); + TextInputComponent onError(String Function(String)? onError); + TextInputComponent validator(bool Function(String)? validator); + TextInputComponent suffixText(TextWrapper? suffixText); + TextInputComponent prefixText(TextWrapper? prefixText); + TextInputComponent prefixIcon(Icon? prefixIcon); + TextInputComponent suffixIcon(Icon? suffixIcon); + TextInputComponent label(TextWrapper? label); + TextInputComponent hint(TextWrapper? hint); + TextInputComponent normalStyle(TextInputStyle? normalStyle); + TextInputComponent focusedStyle(TextInputStyle? focusedStyle); + TextInputComponent errorStyle(TextInputStyle? errorStyle); + TextInputComponent disableStyle(TextInputStyle? disableStyle); TextInputComponent controller(TextEditingController? controller); TextInputComponent focusNode(FocusNode? focusNode); - TextInputComponent decoration(InputDecoration? decoration); TextInputComponent keyboardType(TextInputType? keyboardType); TextInputComponent smartDashesType(SmartDashesType? smartDashesType); TextInputComponent smartQuotesType(SmartQuotesType? smartQuotesType); @@ -44,7 +53,7 @@ abstract class $TextInputComponentCWProxy { TextInputComponent onAppPrivateCommand( void Function(String, Map)? onAppPrivateCommand); TextInputComponent inputFormatters(List? inputFormatters); - TextInputComponent enabled(bool? enabled); + TextInputComponent enabled(ValueNotifier? enabled); TextInputComponent cursorWidth(double? cursorWidth); TextInputComponent cursorHeight(double? cursorHeight); TextInputComponent cursorRadius(Radius? cursorRadius); @@ -76,12 +85,21 @@ abstract class $TextInputComponentCWProxy { TextMagnifierConfiguration? magnifierConfiguration); TextInputComponent key(Key? key); TextInputComponent call({ - MultiColor? backgroundColors, - MultiColor? borderColors, - double? radius, + bool? expand, + String Function(String)? onError, + bool Function(String)? validator, + TextWrapper? suffixText, + TextWrapper? prefixText, + Icon? prefixIcon, + Icon? suffixIcon, + TextWrapper? label, + TextWrapper? hint, + TextInputStyle? normalStyle, + TextInputStyle? focusedStyle, + TextInputStyle? errorStyle, + TextInputStyle? disableStyle, TextEditingController? controller, FocusNode? focusNode, - InputDecoration? decoration, TextInputType? keyboardType, SmartDashesType? smartDashesType, SmartQuotesType? smartQuotesType, @@ -110,7 +128,7 @@ abstract class $TextInputComponentCWProxy { void Function(String)? onSubmitted, void Function(String, Map)? onAppPrivateCommand, List? inputFormatters, - bool? enabled, + ValueNotifier? enabled, double? cursorWidth, double? cursorHeight, Radius? cursorRadius, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart new file mode 100644 index 00000000..a456647e --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart @@ -0,0 +1,102 @@ +// 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:copy_with_extension/copy_with_extension.dart'; +import 'package:flutter/material.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; +part 'text_input_style.g.dart'; + +@CopyWith() +class TextInputStyle { + TextInputStyle({ + this.labelStyle, + this.hintStyle, + this.backgroundColors, + this.borderColors, + this.boxShadow, + this.radius, + this.inputStyle, + this.iconColor, + this.prefixStyle, + this.prefixIconColor, + this.suffixStyle, + this.suffixIconColor, + }); + + final TextStyle? labelStyle; + final TextStyle? hintStyle; + + final Color? iconColor; + final TextStyle? prefixStyle; + final Color? prefixIconColor; + final TextStyle? suffixStyle; + final Color? suffixIconColor; + + final MultiColor? backgroundColors; + final MultiColor? borderColors; + final BoxShadow? boxShadow; + final BorderRadiusGeometry? radius; + final TextStyle? inputStyle; + + static TextInputStyle? merge(TextInputStyle? a, TextInputStyle? b) { + if (b == null) { + return a?.copyWith(); + } + if (a == null) { + return b.copyWith(); + } + return a.copyWith( + labelStyle: b.labelStyle, + hintStyle: b.hintStyle, + backgroundColors: b.backgroundColors, + borderColors: b.borderColors, + boxShadow: b.boxShadow, + radius: b.radius, + inputStyle: b.inputStyle, + iconColor: b.iconColor, + prefixStyle: b.prefixStyle, + prefixIconColor: b.prefixIconColor, + suffixIconColor: b.suffixIconColor, + suffixStyle: b.suffixStyle, + ); + } + + static TextInputStyle? lerp( + TextInputStyle? a, + TextInputStyle? b, + double t, + ) { + if (a == null || b == null) { + return null; + } + + return b.copyWith( + labelStyle: TextStyle.lerp(a.labelStyle, b.labelStyle, t), + hintStyle: TextStyle.lerp(a.hintStyle, b.hintStyle, t), + backgroundColors: + MultiColor.lerp(a.backgroundColors, b.backgroundColors, t), + radius: BorderRadiusGeometry.lerp(a.radius, b.radius, t), + borderColors: MultiColor.lerp(a.borderColors, b.borderColors, t), + boxShadow: BoxShadow.lerp(a.boxShadow, b.boxShadow, t), + inputStyle: TextStyle.lerp(a.inputStyle, b.inputStyle, t), + prefixStyle: TextStyle.lerp(a.prefixStyle, b.prefixStyle, t), + suffixStyle: TextStyle.lerp(a.suffixStyle, b.suffixStyle, t), + prefixIconColor: Color.lerp(a.prefixIconColor, b.prefixIconColor, t), + suffixIconColor: Color.lerp(a.suffixIconColor, b.suffixIconColor, t), + iconColor: Color.lerp(a.iconColor, b.iconColor, t), + ); + } +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.g.dart new file mode 100644 index 00000000..972c2b88 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.g.dart @@ -0,0 +1,185 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'text_input_style.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$TextInputStyleCWProxy { + TextInputStyle labelStyle(TextStyle? labelStyle); + + TextInputStyle hintStyle(TextStyle? hintStyle); + + TextInputStyle backgroundColors(MultiColor? backgroundColors); + + TextInputStyle borderColors(MultiColor? borderColors); + + TextInputStyle boxShadow(BoxShadow? boxShadow); + + TextInputStyle radius(BorderRadiusGeometry? radius); + + TextInputStyle inputStyle(TextStyle? inputStyle); + + TextInputStyle iconColor(Color? iconColor); + + TextInputStyle prefixStyle(TextStyle? prefixStyle); + + TextInputStyle prefixIconColor(Color? prefixIconColor); + + TextInputStyle suffixStyle(TextStyle? suffixStyle); + + TextInputStyle suffixIconColor(Color? suffixIconColor); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TextInputStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TextInputStyle(...).copyWith(id: 12, name: "My name") + /// ```` + TextInputStyle call({ + TextStyle? labelStyle, + TextStyle? hintStyle, + MultiColor? backgroundColors, + MultiColor? borderColors, + BoxShadow? boxShadow, + BorderRadiusGeometry? radius, + TextStyle? inputStyle, + Color? iconColor, + TextStyle? prefixStyle, + Color? prefixIconColor, + TextStyle? suffixStyle, + Color? suffixIconColor, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTextInputStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTextInputStyle.copyWith.fieldName(...)` +class _$TextInputStyleCWProxyImpl implements _$TextInputStyleCWProxy { + const _$TextInputStyleCWProxyImpl(this._value); + + final TextInputStyle _value; + + @override + TextInputStyle labelStyle(TextStyle? labelStyle) => + this(labelStyle: labelStyle); + + @override + TextInputStyle hintStyle(TextStyle? hintStyle) => this(hintStyle: hintStyle); + + @override + TextInputStyle backgroundColors(MultiColor? backgroundColors) => + this(backgroundColors: backgroundColors); + + @override + TextInputStyle borderColors(MultiColor? borderColors) => + this(borderColors: borderColors); + + @override + TextInputStyle boxShadow(BoxShadow? boxShadow) => this(boxShadow: boxShadow); + + @override + TextInputStyle radius(BorderRadiusGeometry? radius) => this(radius: radius); + + @override + TextInputStyle inputStyle(TextStyle? inputStyle) => + this(inputStyle: inputStyle); + + @override + TextInputStyle iconColor(Color? iconColor) => this(iconColor: iconColor); + + @override + TextInputStyle prefixStyle(TextStyle? prefixStyle) => + this(prefixStyle: prefixStyle); + + @override + TextInputStyle prefixIconColor(Color? prefixIconColor) => + this(prefixIconColor: prefixIconColor); + + @override + TextInputStyle suffixStyle(TextStyle? suffixStyle) => + this(suffixStyle: suffixStyle); + + @override + TextInputStyle suffixIconColor(Color? suffixIconColor) => + this(suffixIconColor: suffixIconColor); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TextInputStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// TextInputStyle(...).copyWith(id: 12, name: "My name") + /// ```` + TextInputStyle call({ + Object? labelStyle = const $CopyWithPlaceholder(), + Object? hintStyle = const $CopyWithPlaceholder(), + Object? backgroundColors = const $CopyWithPlaceholder(), + Object? borderColors = const $CopyWithPlaceholder(), + Object? boxShadow = const $CopyWithPlaceholder(), + Object? radius = const $CopyWithPlaceholder(), + Object? inputStyle = const $CopyWithPlaceholder(), + Object? iconColor = const $CopyWithPlaceholder(), + Object? prefixStyle = const $CopyWithPlaceholder(), + Object? prefixIconColor = const $CopyWithPlaceholder(), + Object? suffixStyle = const $CopyWithPlaceholder(), + Object? suffixIconColor = const $CopyWithPlaceholder(), + }) { + return TextInputStyle( + labelStyle: labelStyle == const $CopyWithPlaceholder() + ? _value.labelStyle + // ignore: cast_nullable_to_non_nullable + : labelStyle as TextStyle?, + hintStyle: hintStyle == const $CopyWithPlaceholder() + ? _value.hintStyle + // ignore: cast_nullable_to_non_nullable + : hintStyle as TextStyle?, + backgroundColors: backgroundColors == const $CopyWithPlaceholder() + ? _value.backgroundColors + // ignore: cast_nullable_to_non_nullable + : backgroundColors as MultiColor?, + borderColors: borderColors == const $CopyWithPlaceholder() + ? _value.borderColors + // ignore: cast_nullable_to_non_nullable + : borderColors as MultiColor?, + boxShadow: boxShadow == const $CopyWithPlaceholder() + ? _value.boxShadow + // ignore: cast_nullable_to_non_nullable + : boxShadow as BoxShadow?, + radius: radius == const $CopyWithPlaceholder() + ? _value.radius + // ignore: cast_nullable_to_non_nullable + : radius as BorderRadiusGeometry?, + inputStyle: inputStyle == const $CopyWithPlaceholder() + ? _value.inputStyle + // ignore: cast_nullable_to_non_nullable + : inputStyle as TextStyle?, + iconColor: iconColor == const $CopyWithPlaceholder() + ? _value.iconColor + // ignore: cast_nullable_to_non_nullable + : iconColor as Color?, + prefixStyle: prefixStyle == const $CopyWithPlaceholder() + ? _value.prefixStyle + // ignore: cast_nullable_to_non_nullable + : prefixStyle as TextStyle?, + prefixIconColor: prefixIconColor == const $CopyWithPlaceholder() + ? _value.prefixIconColor + // ignore: cast_nullable_to_non_nullable + : prefixIconColor as Color?, + suffixStyle: suffixStyle == const $CopyWithPlaceholder() + ? _value.suffixStyle + // ignore: cast_nullable_to_non_nullable + : suffixStyle as TextStyle?, + suffixIconColor: suffixIconColor == const $CopyWithPlaceholder() + ? _value.suffixIconColor + // ignore: cast_nullable_to_non_nullable + : suffixIconColor as Color?, + ); + } +} + +extension $TextInputStyleCopyWith on TextInputStyle { + /// Returns a callable class that can be used as follows: `instanceOfTextInputStyle.copyWith(...)` or like so:`instanceOfTextInputStyle.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$TextInputStyleCWProxy get copyWith => _$TextInputStyleCWProxyImpl(this); +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_inputs.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_inputs.dart new file mode 100644 index 00000000..26b4e465 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_inputs.dart @@ -0,0 +1,18 @@ +// 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 . + +export './text_input_component.dart'; +export './text_input_style.dart'; -- 2.47.2 From 1edb1f732485de0360ad2cb3ee01cbc269f30eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 08:22:20 +0100 Subject: [PATCH 07/25] feat(ui_kit): implemement text inputs (#138) --- .../file_selection_button_screen.dart | 36 +- .../file_selection_button_theme_resolver.dart | 46 +- .../flat_button/flat_button_screen.dart | 24 +- .../flat_button_theme_resolver.dart | 28 +- .../simple_icon_button_theme_resolver.dart | 30 +- .../simple_icon_screen.dart | 24 +- .../symbol_button/symbol_button_screen.dart | 35 +- .../symbol_button_theme_resolver.dart | 41 +- .../cards/widgets/card_wrapper.dart | 8 +- .../lib/src/components/components.dart | 1 + .../gradients/gradient_box_border.dart | 8 +- .../text_inputs/cubit/text_input_cubit.dart | 57 +++ .../text_inputs/cubit/text_input_state.dart | 49 +++ .../components/text_inputs/text_input.dart | 168 ++++++++ .../components/text_inputs/text_input.g.dart | 348 +++++++++++++++ .../text_inputs/text_input_screen.dart | 396 ++++++++++++++++++ .../text_input_theme_resolver.dart | 172 ++++++++ .../text_inputs/widgets/label_widget.dart | 37 ++ .../widgets/text_input_wrapper.dart | 60 +++ .../src/core/extensions/theme_extensions.dart | 2 + .../lib/src/core/helpers/theme_helper.dart | 33 ++ .../wyatt_ui_kit/lib/src/domain/domain.dart | 4 + ...n.dart => text_input_theme_extension.dart} | 25 +- 23 files changed, 1468 insertions(+), 164 deletions(-) create mode 100644 packages/wyatt_ui_kit/lib/src/components/text_inputs/cubit/text_input_cubit.dart create mode 100644 packages/wyatt_ui_kit/lib/src/components/text_inputs/cubit/text_input_state.dart create mode 100644 packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input.dart create mode 100644 packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input.g.dart create mode 100644 packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart create mode 100644 packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart create mode 100644 packages/wyatt_ui_kit/lib/src/components/text_inputs/widgets/label_widget.dart create mode 100644 packages/wyatt_ui_kit/lib/src/components/text_inputs/widgets/text_input_wrapper.dart create mode 100644 packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart rename packages/wyatt_ui_kit/lib/src/domain/{input_text_theme_extension.dart => text_input_theme_extension.dart} (67%) 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 bc45bec9..18a2cf0b 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 @@ -67,41 +67,7 @@ class FileSelectionButtonScreen FileSelectionButtonStyle _resolve(BuildContext context, ButtonState state) { final FileSelectionButtonThemeResolver resolver = themeResolver ?? FileSelectionButtonThemeResolver( - computeExtensionValueFn: ( - context, - defaultValue, - themeExtension, { - extra, - }) { - FileSelectionButtonStyle? style = defaultValue; - switch (extra?.state) { - case ControlState.disabled: - style = themeExtension.disabledStyle; - break; - case ControlState.focused: - style = themeExtension.focusedStyle; - break; - case ControlState.hovered: - style = themeExtension.hoveredStyle; - break; - case ControlState.tapped: - style = themeExtension.tappedStyle; - break; - case ControlState.normal: - case null: - style = themeExtension.normalStyle; - break; - } - if (extra?.isSelected ?? false) { - style = themeExtension.selectedStyle; - } - if (extra?.isInvalid ?? false) { - style = themeExtension.invalidStyle; - } - - return style; - }, - customStyleFn: (context, {extra}) { + customStyleFn: (context, extensionValue, {extra}) { FileSelectionButtonStyle? style; switch (extra?.state) { case ControlState.disabled: diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart index 7c1f9634..92399773 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart @@ -22,7 +22,6 @@ import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; class FileSelectionButtonThemeResolver extends ThemeResolver< FileSelectionButtonStyle, FileSelectionButtonThemeExtension, ButtonState> { const FileSelectionButtonThemeResolver({ - required this.computeExtensionValueFn, required this.customStyleFn, }); @@ -57,8 +56,7 @@ class FileSelectionButtonThemeResolver extends ThemeResolver< } if (extra?.isInvalid ?? false) { - backgroundColor = - MultiColor.single(context.colorScheme.error); + backgroundColor = MultiColor.single(context.colorScheme.error); } return FileSelectionButtonStyle( @@ -75,15 +73,43 @@ class FileSelectionButtonThemeResolver extends ThemeResolver< @override final FileSelectionButtonStyle? Function( + BuildContext context, + FileSelectionButtonStyle? extensionValue, { + ButtonState? extra, + }) customStyleFn; + + @override + FileSelectionButtonStyle? computeExtensionValueFn( BuildContext context, FileSelectionButtonStyle defaultValue, FileSelectionButtonThemeExtension themeExtension, { ButtonState? extra, - }) computeExtensionValueFn; - - @override - final FileSelectionButtonStyle? Function( - BuildContext context, { - ButtonState? extra, - }) customStyleFn; + }) { + FileSelectionButtonStyle? style = defaultValue; + switch (extra?.state) { + case ControlState.disabled: + style = themeExtension.disabledStyle; + break; + case ControlState.focused: + style = themeExtension.focusedStyle; + break; + case ControlState.hovered: + style = themeExtension.hoveredStyle; + break; + case ControlState.tapped: + style = themeExtension.tappedStyle; + break; + case ControlState.normal: + case null: + style = themeExtension.normalStyle; + break; + } + if (extra?.isSelected ?? false) { + style = themeExtension.selectedStyle; + } + if (extra?.isInvalid ?? false) { + style = themeExtension.invalidStyle; + } + return style; + } } 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 803c68cc..88ff27f5 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 @@ -61,27 +61,7 @@ class FlatButtonScreen extends CubitScreen { FlatButtonStyle _resolve(BuildContext context, ControlState state) { final FlatButtonThemeResolver resolver = themeResolver ?? FlatButtonThemeResolver( - computeExtensionValueFn: ( - context, - defaultValue, - themeExtension, { - extra, - }) { - switch (extra) { - case ControlState.disabled: - return themeExtension.disabledStyle; - case ControlState.focused: - return themeExtension.focusedStyle; - case ControlState.hovered: - return themeExtension.hoveredStyle; - case ControlState.tapped: - return themeExtension.tappedStyle; - case ControlState.normal: - case null: - return themeExtension.normalStyle; - } - }, - customStyleFn: (context, {extra}) { + customStyleFn: (context, extensionValue, {extra}) { switch (extra) { case ControlState.disabled: return disabledStyle; @@ -141,7 +121,7 @@ class FlatButtonScreen extends CubitScreen { // If no border color => no default value border: (style.borderColors != null && style.stroke != null) ? (style.borderColors?.isGradient ?? false) - ? GradientBoxBorder( + ? CustomGradientBoxBorder( gradient: LinearGradient( colors: style.borderColors!.colors, ), diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_theme_resolver.dart index c48c6b8e..cef92e2f 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_theme_resolver.dart @@ -21,7 +21,6 @@ import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; class FlatButtonThemeResolver extends ThemeResolver { const FlatButtonThemeResolver({ - required this.computeExtensionValueFn, required this.customStyleFn, }); @@ -70,13 +69,30 @@ class FlatButtonThemeResolver extends ThemeResolver { const SimpleIconButtonThemeResolver({ - required this.computeExtensionValueFn, required this.customStyleFn, }); @@ -68,15 +67,30 @@ class SimpleIconButtonThemeResolver extends ThemeResolver { SimpleIconButtonStyle _resolve(BuildContext context, ControlState state) { final SimpleIconButtonThemeResolver resolver = themeResolver ?? SimpleIconButtonThemeResolver( - computeExtensionValueFn: ( - context, - defaultValue, - themeExtension, { - extra, - }) { - switch (extra) { - case ControlState.disabled: - return themeExtension.disabledStyle; - case ControlState.focused: - return themeExtension.focusedStyle; - case ControlState.hovered: - return themeExtension.hoveredStyle; - case ControlState.tapped: - return themeExtension.tappedStyle; - case ControlState.normal: - case null: - return themeExtension.normalStyle; - } - }, - customStyleFn: (context, {extra}) { + customStyleFn: (context, extensionValue, {extra}) { switch (extra) { case ControlState.disabled: return disabledStyle; @@ -140,7 +120,7 @@ class SimpleIconButtonScreen extends CubitScreen { // If no border color => no default value border: (style.borderColors != null && style.stroke != null) ? (style.borderColors?.isGradient ?? false) - ? GradientBoxBorder( + ? CustomGradientBoxBorder( gradient: LinearGradient( colors: style.borderColors!.colors, ), 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 b8c84633..e2e427fd 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 @@ -63,38 +63,7 @@ class SymbolButtonScreen SymbolButtonStyle _resolve(BuildContext context, ButtonState state) { final SymbolButtonThemeResolver resolver = themeResolver ?? SymbolButtonThemeResolver( - computeExtensionValueFn: ( - context, - defaultValue, - themeExtension, { - extra, - }) { - SymbolButtonStyle? style = defaultValue; - switch (extra?.state) { - case ControlState.disabled: - style = themeExtension.disabledStyle; - break; - case ControlState.focused: - style = themeExtension.focusedStyle; - break; - case ControlState.hovered: - style = themeExtension.hoveredStyle; - break; - case ControlState.tapped: - style = themeExtension.tappedStyle; - break; - case ControlState.normal: - case null: - style = themeExtension.normalStyle; - break; - } - if (extra?.isSelected ?? false) { - style = themeExtension.selectedStyle; - } - - return style; - }, - customStyleFn: (context, {extra}) { + customStyleFn: (context, extensionValue, {extra}) { SymbolButtonStyle? style; switch (extra?.state) { case ControlState.disabled: @@ -175,7 +144,7 @@ class SymbolButtonScreen border: (style.borderColors != null && style.stroke != null) ? (style.borderColors?.isGradient ?? false) - ? GradientBoxBorder( + ? CustomGradientBoxBorder( gradient: LinearGradient( colors: style.borderColors!.colors, ), diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart index 8d679e22..bed01568 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart @@ -22,7 +22,6 @@ import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; class SymbolButtonThemeResolver extends ThemeResolver { const SymbolButtonThemeResolver({ - required this.computeExtensionValueFn, required this.customStyleFn, }); @@ -58,7 +57,7 @@ class SymbolButtonThemeResolver extends ThemeResolver { BoxBorder? _boxBorder(BuildContext context) { if (widget.borderColors != null) { if (widget.borderColors!.length >= 2) { - return GradientBoxBorder( + return CustomGradientBoxBorder( gradient: LinearGradient( colors: widget.borderColors!, ), @@ -151,9 +151,15 @@ class _CardWrapperState extends State { final extensionCardColor = Theme.of(context).extension(); if (extensionCardColor != null && +<<<<<<< HEAD extensionCardColor.borderColors != null) { if (extensionCardColor.borderColors!.isGradient) { return GradientBoxBorder( +======= + extensionCardColor.borderColor != null) { + if (extensionCardColor.borderColor!.length >= 2) { + return CustomGradientBoxBorder( +>>>>>>> 548df1c (feat(ui_kit): implemement text inputs (#138)) gradient: LinearGradient( colors: extensionCardColor.borderColors!.colors, ), diff --git a/packages/wyatt_ui_kit/lib/src/components/components.dart b/packages/wyatt_ui_kit/lib/src/components/components.dart index e78cb40d..34d4753d 100644 --- a/packages/wyatt_ui_kit/lib/src/components/components.dart +++ b/packages/wyatt_ui_kit/lib/src/components/components.dart @@ -19,3 +19,4 @@ export './cards/cards.dart'; export './gradients/gradients.dart'; export './loader/loader.dart'; export './rich_text_builder/rich_text_builder.dart'; +export './text_inputs/text_input.dart'; diff --git a/packages/wyatt_ui_kit/lib/src/components/gradients/gradient_box_border.dart b/packages/wyatt_ui_kit/lib/src/components/gradients/gradient_box_border.dart index 912a9c53..10372a96 100644 --- a/packages/wyatt_ui_kit/lib/src/components/gradients/gradient_box_border.dart +++ b/packages/wyatt_ui_kit/lib/src/components/gradients/gradient_box_border.dart @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'package:flutter/material.dart'; import 'package:flutter/painting.dart'; -class GradientBoxBorder extends BoxBorder { - const GradientBoxBorder({this.gradient, this.width = 1}); +class CustomGradientBoxBorder extends Border { + const CustomGradientBoxBorder({this.gradient, this.width = 1}); final Gradient? gradient; final double width; @@ -34,9 +35,6 @@ class GradientBoxBorder extends BoxBorder { @override bool get isUniform => true; - @override - ShapeBorder scale(double t) => this; - @override void paint( Canvas canvas, diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/cubit/text_input_cubit.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/cubit/text_input_cubit.dart new file mode 100644 index 00000000..4c50a1b9 --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/cubit/text_input_cubit.dart @@ -0,0 +1,57 @@ +// 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 'dart:async'; + +import 'package:equatable/equatable.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; + +part 'text_input_state.dart'; + +class TextInputCubit extends Cubit { + TextInputCubit() : super(const TextInputState.initial()); + + // ControlState logic + FutureOr onFocus() async { + if (state.controlState != ControlState.disabled) { + emit(state.copyWith(controlState: ControlState.focused)); + } + } + + FutureOr onUnfocus() async { + if (state.controlState != ControlState.disabled) { + emit(state.copyWith(controlState: ControlState.normal)); + } + } + + Future disable() async { + emit(state.copyWith(controlState: ControlState.disabled)); + } + + Future enable() async { + emit(state.copyWith(controlState: ControlState.normal)); + } + + // StatusState logic + FutureOr onInvalid(String? error) async { + emit(state.copyWith(statusState: StatusState.error, statusMessage: error)); + } + + FutureOr onSuccess() async { + emit(state.copyWith(statusState: StatusState.initial, statusMessage: '')); + } +} diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/cubit/text_input_state.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/cubit/text_input_state.dart new file mode 100644 index 00000000..2b91bd2d --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/cubit/text_input_state.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 . + +part of 'text_input_cubit.dart'; + +class TextInputState extends Equatable { + const TextInputState({ + required this.controlState, + required this.statusState, + this.statusMessage, + }); + + const TextInputState.initial() + : controlState = ControlState.normal, + statusState = StatusState.initial, + statusMessage = null; + + final ControlState controlState; + final StatusState statusState; + + final String? statusMessage; + + @override + List get props => [controlState, statusState, statusMessage]; + + TextInputState copyWith({ + ControlState? controlState, + StatusState? statusState, + String? statusMessage, + }) => + TextInputState( + controlState: controlState ?? this.controlState, + statusState: statusState ?? this.statusState, + statusMessage: statusMessage ?? this.statusMessage, + ); +} diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input.dart new file mode 100644 index 00000000..8e5139c7 --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input.dart @@ -0,0 +1,168 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// super 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. +// +// super 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 super program. If not, see . + +import 'dart:ui'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +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/text_inputs/text_input_screen.dart'; +part 'text_input.g.dart'; + +@ComponentCopyWithExtension() +class TextInput extends TextInputComponent with $TextInputCWMixin { + TextInput({ + super.expand, + super.validator, + super.key, + super.prefixIcon, + super.prefixText, + super.suffixIcon, + super.suffixText, + super.label, + super.onError, + super.hint, + super.normalStyle, + super.focusedStyle, + super.errorStyle, + super.disableStyle, + super.controller, + super.focusNode, + super.keyboardType, + super.smartDashesType, + super.smartQuotesType, + super.enableInteractiveSelection, + super.textInputAction, + super.textCapitalization, + super.style, + super.strutStyle, + super.textAlign, + super.textAlignVertical, + super.textDirection, + super.readOnly, + super.showCursor, + super.autofocus, + super.obscuringCharacter, + super.obscureText, + super.autocorrect, + super.enableSuggestions, + super.maxLines, + super.minLines, + super.expands, + super.maxLength, + super.maxLengthEnforcement, + super.onChanged, + super.onEditingComplete, + super.onSubmitted, + super.onAppPrivateCommand, + super.inputFormatters, + super.enabled, + super.cursorWidth, + super.cursorHeight, + super.cursorRadius, + super.cursorColor, + super.selectionHeightStyle, + super.selectionWidthStyle, + super.keyboardAppearance, + super.scrollPadding, + super.dragStartBehavior, + super.selectionControls, + super.onTap, + super.onTapOutside, + super.mouseCursor, + super.scrollController, + super.scrollPhysics, + super.autofillHints, + super.clipBehavior, + super.restorationId, + super.scribbleEnabled, + super.enableIMEPersonalizedLearning, + super.contextMenuBuilder, + super.spellCheckConfiguration, + super.magnifierConfiguration, + }); + + @override + Widget build(BuildContext context) => TextInputScreen( + expand: expand, + validator: validator, + label: label, + onError: onError, + hint: hint, + focusedStyle: focusedStyle, + normalStyle: normalStyle, + errorStyle: errorStyle, + disableStyle: disableStyle, + prefixIcon: prefixIcon, + prefixText: prefixText, + suffixIcon: suffixIcon, + magnifierConfiguration: magnifierConfiguration, + controller: controller, + focusNode: focusNode, + keyboardType: keyboardType, + textInputAction: textInputAction, + textCapitalization: textCapitalization, + style: style, + strutStyle: strutStyle, + textAlign: textAlign, + textAlignVertical: textAlignVertical, + textDirection: textDirection, + autofocus: autofocus, + obscuringCharacter: obscuringCharacter, + obscureText: obscureText, + autocorrect: autocorrect, + smartDashesType: smartDashesType, + smartQuotesType: smartQuotesType, + enableSuggestions: enableSuggestions, + maxLines: maxLines, + minLines: minLines, + expands: expands, + readOnly: readOnly, + showCursor: showCursor, + maxLength: maxLength, + maxLengthEnforcement: maxLengthEnforcement, + onChanged: onChanged, + onEditingComplete: onEditingComplete, + onSubmitted: onSubmitted, + onAppPrivateCommand: onAppPrivateCommand, + inputFormatters: inputFormatters, + enabled: enabled, + cursorWidth: cursorWidth, + cursorHeight: cursorHeight, + cursorRadius: cursorRadius, + cursorColor: cursorColor, + selectionHeightStyle: selectionHeightStyle, + selectionWidthStyle: selectionWidthStyle, + keyboardAppearance: keyboardAppearance, + scrollPadding: scrollPadding, + enableInteractiveSelection: enableInteractiveSelection, + selectionControls: selectionControls, + dragStartBehavior: dragStartBehavior, + onTap: onTap, + onTapOutside: onTapOutside, + mouseCursor: mouseCursor, + scrollPhysics: scrollPhysics, + scrollController: scrollController, + autofillHints: autofillHints, + clipBehavior: clipBehavior, + restorationId: restorationId, + scribbleEnabled: scribbleEnabled, + enableIMEPersonalizedLearning: enableIMEPersonalizedLearning, + contextMenuBuilder: contextMenuBuilder, + spellCheckConfiguration: spellCheckConfiguration, + ); +} diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input.g.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input.g.dart new file mode 100644 index 00000000..2547f95c --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input.g.dart @@ -0,0 +1,348 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'text_input.dart'; + +// ************************************************************************** +// ComponentCopyWithGenerator +// ************************************************************************** + +class $TextInputCWProxyImpl implements $TextInputComponentCWProxy { + const $TextInputCWProxyImpl(this._value); + final TextInput _value; + @override + TextInput expand(bool? expand) => this(expand: expand); + @override + TextInput onError(String Function(String)? onError) => this(onError: onError); + @override + TextInput validator(bool Function(String)? validator) => + this(validator: validator); + @override + TextInput suffixText(TextWrapper? suffixText) => this(suffixText: suffixText); + @override + TextInput prefixText(TextWrapper? prefixText) => this(prefixText: prefixText); + @override + TextInput prefixIcon(Icon? prefixIcon) => this(prefixIcon: prefixIcon); + @override + TextInput suffixIcon(Icon? suffixIcon) => this(suffixIcon: suffixIcon); + @override + TextInput label(TextWrapper? label) => this(label: label); + @override + TextInput hint(TextWrapper? hint) => this(hint: hint); + @override + TextInput normalStyle(TextInputStyle? normalStyle) => + this(normalStyle: normalStyle); + @override + TextInput focusedStyle(TextInputStyle? focusedStyle) => + this(focusedStyle: focusedStyle); + @override + TextInput errorStyle(TextInputStyle? errorStyle) => + this(errorStyle: errorStyle); + @override + TextInput disableStyle(TextInputStyle? disableStyle) => + this(disableStyle: disableStyle); + @override + TextInput controller(TextEditingController? controller) => + this(controller: controller); + @override + TextInput focusNode(FocusNode? focusNode) => this(focusNode: focusNode); + @override + TextInput keyboardType(TextInputType? keyboardType) => + this(keyboardType: keyboardType); + @override + TextInput smartDashesType(SmartDashesType? smartDashesType) => + this(smartDashesType: smartDashesType); + @override + TextInput smartQuotesType(SmartQuotesType? smartQuotesType) => + this(smartQuotesType: smartQuotesType); + @override + TextInput enableInteractiveSelection(bool? enableInteractiveSelection) => + this(enableInteractiveSelection: enableInteractiveSelection); + @override + TextInput textInputAction(TextInputAction? textInputAction) => + this(textInputAction: textInputAction); + @override + TextInput textCapitalization(TextCapitalization? textCapitalization) => + this(textCapitalization: textCapitalization); + @override + TextInput style(TextStyle? style) => this(style: style); + @override + TextInput strutStyle(StrutStyle? strutStyle) => this(strutStyle: strutStyle); + @override + TextInput textAlign(TextAlign? textAlign) => this(textAlign: textAlign); + @override + TextInput textAlignVertical(TextAlignVertical? textAlignVertical) => + this(textAlignVertical: textAlignVertical); + @override + TextInput textDirection(TextDirection? textDirection) => + this(textDirection: textDirection); + @override + TextInput readOnly(bool? readOnly) => this(readOnly: readOnly); + @override + TextInput showCursor(bool? showCursor) => this(showCursor: showCursor); + @override + TextInput autofocus(bool? autofocus) => this(autofocus: autofocus); + @override + TextInput obscuringCharacter(String? obscuringCharacter) => + this(obscuringCharacter: obscuringCharacter); + @override + TextInput obscureText(bool? obscureText) => this(obscureText: obscureText); + @override + TextInput autocorrect(bool? autocorrect) => this(autocorrect: autocorrect); + @override + TextInput enableSuggestions(bool? enableSuggestions) => + this(enableSuggestions: enableSuggestions); + @override + TextInput maxLines(int? maxLines) => this(maxLines: maxLines); + @override + TextInput minLines(int? minLines) => this(minLines: minLines); + @override + TextInput expands(bool? expands) => this(expands: expands); + @override + TextInput maxLength(int? maxLength) => this(maxLength: maxLength); + @override + TextInput maxLengthEnforcement(MaxLengthEnforcement? maxLengthEnforcement) => + this(maxLengthEnforcement: maxLengthEnforcement); + @override + TextInput onChanged(void Function(String)? onChanged) => + this(onChanged: onChanged); + @override + TextInput onEditingComplete(void Function()? onEditingComplete) => + this(onEditingComplete: onEditingComplete); + @override + TextInput onSubmitted(void Function(String)? onSubmitted) => + this(onSubmitted: onSubmitted); + @override + TextInput onAppPrivateCommand( + void Function(String, Map)? onAppPrivateCommand) => + this(onAppPrivateCommand: onAppPrivateCommand); + @override + TextInput inputFormatters(List? inputFormatters) => + this(inputFormatters: inputFormatters); + @override + TextInput enabled(ValueNotifier? enabled) => this(enabled: enabled); + @override + TextInput cursorWidth(double? cursorWidth) => this(cursorWidth: cursorWidth); + @override + TextInput cursorHeight(double? cursorHeight) => + this(cursorHeight: cursorHeight); + @override + TextInput cursorRadius(Radius? cursorRadius) => + this(cursorRadius: cursorRadius); + @override + TextInput cursorColor(Color? cursorColor) => this(cursorColor: cursorColor); + @override + TextInput selectionHeightStyle(BoxHeightStyle? selectionHeightStyle) => + this(selectionHeightStyle: selectionHeightStyle); + @override + TextInput selectionWidthStyle(BoxWidthStyle? selectionWidthStyle) => + this(selectionWidthStyle: selectionWidthStyle); + @override + TextInput keyboardAppearance(Brightness? keyboardAppearance) => + this(keyboardAppearance: keyboardAppearance); + @override + TextInput scrollPadding(EdgeInsets? scrollPadding) => + this(scrollPadding: scrollPadding); + @override + TextInput dragStartBehavior(DragStartBehavior? dragStartBehavior) => + this(dragStartBehavior: dragStartBehavior); + @override + TextInput selectionControls(TextSelectionControls? selectionControls) => + this(selectionControls: selectionControls); + @override + TextInput onTap(void Function()? onTap) => this(onTap: onTap); + @override + TextInput onTapOutside(void Function(PointerDownEvent)? onTapOutside) => + this(onTapOutside: onTapOutside); + @override + TextInput mouseCursor(MouseCursor? mouseCursor) => + this(mouseCursor: mouseCursor); + @override + TextInput scrollController(ScrollController? scrollController) => + this(scrollController: scrollController); + @override + TextInput scrollPhysics(ScrollPhysics? scrollPhysics) => + this(scrollPhysics: scrollPhysics); + @override + TextInput autofillHints(Iterable? autofillHints) => + this(autofillHints: autofillHints); + @override + TextInput clipBehavior(Clip? clipBehavior) => + this(clipBehavior: clipBehavior); + @override + TextInput restorationId(String? restorationId) => + this(restorationId: restorationId); + @override + TextInput scribbleEnabled(bool? scribbleEnabled) => + this(scribbleEnabled: scribbleEnabled); + @override + TextInput enableIMEPersonalizedLearning( + bool? enableIMEPersonalizedLearning) => + this(enableIMEPersonalizedLearning: enableIMEPersonalizedLearning); + @override + TextInput contextMenuBuilder( + Widget Function(BuildContext, EditableTextState)? + contextMenuBuilder) => + this(contextMenuBuilder: contextMenuBuilder); + @override + TextInput spellCheckConfiguration( + SpellCheckConfiguration? spellCheckConfiguration) => + this(spellCheckConfiguration: spellCheckConfiguration); + @override + TextInput magnifierConfiguration( + TextMagnifierConfiguration? magnifierConfiguration) => + this(magnifierConfiguration: magnifierConfiguration); + @override + TextInput key(Key? key) => this(key: key); + @override + TextInput call({ + bool? expand, + String Function(String)? onError, + bool Function(String)? validator, + TextWrapper? suffixText, + TextWrapper? prefixText, + Icon? prefixIcon, + Icon? suffixIcon, + TextWrapper? label, + TextWrapper? hint, + TextInputStyle? normalStyle, + TextInputStyle? focusedStyle, + TextInputStyle? errorStyle, + TextInputStyle? disableStyle, + TextEditingController? controller, + FocusNode? focusNode, + TextInputType? keyboardType, + SmartDashesType? smartDashesType, + SmartQuotesType? smartQuotesType, + bool? enableInteractiveSelection, + TextInputAction? textInputAction, + TextCapitalization? textCapitalization, + TextStyle? style, + StrutStyle? strutStyle, + TextAlign? textAlign, + TextAlignVertical? textAlignVertical, + TextDirection? textDirection, + bool? readOnly, + bool? showCursor, + bool? autofocus, + String? obscuringCharacter, + bool? obscureText, + bool? autocorrect, + bool? enableSuggestions, + int? maxLines, + int? minLines, + bool? expands, + int? maxLength, + MaxLengthEnforcement? maxLengthEnforcement, + void Function(String)? onChanged, + void Function()? onEditingComplete, + void Function(String)? onSubmitted, + void Function(String, Map)? onAppPrivateCommand, + List? inputFormatters, + ValueNotifier? enabled, + double? cursorWidth, + double? cursorHeight, + Radius? cursorRadius, + Color? cursorColor, + BoxHeightStyle? selectionHeightStyle, + BoxWidthStyle? selectionWidthStyle, + Brightness? keyboardAppearance, + EdgeInsets? scrollPadding, + DragStartBehavior? dragStartBehavior, + TextSelectionControls? selectionControls, + void Function()? onTap, + void Function(PointerDownEvent)? onTapOutside, + MouseCursor? mouseCursor, + ScrollController? scrollController, + ScrollPhysics? scrollPhysics, + Iterable? autofillHints, + Clip? clipBehavior, + String? restorationId, + bool? scribbleEnabled, + bool? enableIMEPersonalizedLearning, + Widget Function(BuildContext, EditableTextState)? contextMenuBuilder, + SpellCheckConfiguration? spellCheckConfiguration, + TextMagnifierConfiguration? magnifierConfiguration, + Key? key, + }) => + TextInput( + expand: expand ?? _value.expand, + validator: validator ?? _value.validator, + key: key ?? _value.key, + prefixIcon: prefixIcon ?? _value.prefixIcon, + prefixText: prefixText ?? _value.prefixText, + suffixIcon: suffixIcon ?? _value.suffixIcon, + suffixText: suffixText ?? _value.suffixText, + label: label ?? _value.label, + onError: onError ?? _value.onError, + hint: hint ?? _value.hint, + normalStyle: normalStyle ?? _value.normalStyle, + focusedStyle: focusedStyle ?? _value.focusedStyle, + errorStyle: errorStyle ?? _value.errorStyle, + disableStyle: disableStyle ?? _value.disableStyle, + controller: controller ?? _value.controller, + focusNode: focusNode ?? _value.focusNode, + keyboardType: keyboardType ?? _value.keyboardType, + smartDashesType: smartDashesType ?? _value.smartDashesType, + smartQuotesType: smartQuotesType ?? _value.smartQuotesType, + enableInteractiveSelection: + enableInteractiveSelection ?? _value.enableInteractiveSelection, + textInputAction: textInputAction ?? _value.textInputAction, + textCapitalization: textCapitalization ?? _value.textCapitalization, + style: style ?? _value.style, + strutStyle: strutStyle ?? _value.strutStyle, + textAlign: textAlign ?? _value.textAlign, + textAlignVertical: textAlignVertical ?? _value.textAlignVertical, + textDirection: textDirection ?? _value.textDirection, + readOnly: readOnly ?? _value.readOnly, + showCursor: showCursor ?? _value.showCursor, + autofocus: autofocus ?? _value.autofocus, + obscuringCharacter: obscuringCharacter ?? _value.obscuringCharacter, + obscureText: obscureText ?? _value.obscureText, + autocorrect: autocorrect ?? _value.autocorrect, + enableSuggestions: enableSuggestions ?? _value.enableSuggestions, + maxLines: maxLines ?? _value.maxLines, + minLines: minLines ?? _value.minLines, + expands: expands ?? _value.expands, + maxLength: maxLength ?? _value.maxLength, + maxLengthEnforcement: + maxLengthEnforcement ?? _value.maxLengthEnforcement, + onChanged: onChanged ?? _value.onChanged, + onEditingComplete: onEditingComplete ?? _value.onEditingComplete, + onSubmitted: onSubmitted ?? _value.onSubmitted, + onAppPrivateCommand: onAppPrivateCommand ?? _value.onAppPrivateCommand, + inputFormatters: inputFormatters ?? _value.inputFormatters, + enabled: enabled ?? _value.enabled, + cursorWidth: cursorWidth ?? _value.cursorWidth, + cursorHeight: cursorHeight ?? _value.cursorHeight, + cursorRadius: cursorRadius ?? _value.cursorRadius, + cursorColor: cursorColor ?? _value.cursorColor, + selectionHeightStyle: + selectionHeightStyle ?? _value.selectionHeightStyle, + selectionWidthStyle: selectionWidthStyle ?? _value.selectionWidthStyle, + keyboardAppearance: keyboardAppearance ?? _value.keyboardAppearance, + scrollPadding: scrollPadding ?? _value.scrollPadding, + dragStartBehavior: dragStartBehavior ?? _value.dragStartBehavior, + selectionControls: selectionControls ?? _value.selectionControls, + onTap: onTap ?? _value.onTap, + onTapOutside: onTapOutside ?? _value.onTapOutside, + mouseCursor: mouseCursor ?? _value.mouseCursor, + scrollController: scrollController ?? _value.scrollController, + scrollPhysics: scrollPhysics ?? _value.scrollPhysics, + autofillHints: autofillHints ?? _value.autofillHints, + clipBehavior: clipBehavior ?? _value.clipBehavior, + restorationId: restorationId ?? _value.restorationId, + scribbleEnabled: scribbleEnabled ?? _value.scribbleEnabled, + enableIMEPersonalizedLearning: enableIMEPersonalizedLearning ?? + _value.enableIMEPersonalizedLearning, + contextMenuBuilder: contextMenuBuilder ?? _value.contextMenuBuilder, + spellCheckConfiguration: + spellCheckConfiguration ?? _value.spellCheckConfiguration, + magnifierConfiguration: + magnifierConfiguration ?? _value.magnifierConfiguration, + ); +} + +mixin $TextInputCWMixin on Component { + $TextInputComponentCWProxy get copyWith => + $TextInputCWProxyImpl(this as TextInput); +} diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart new file mode 100644 index 00000000..51a9d291 --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart @@ -0,0 +1,396 @@ +// 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 'dart:ui'; + +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +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/text_inputs/cubit/text_input_cubit.dart'; +import 'package:wyatt_ui_kit/src/components/text_inputs/text_input_theme_resolver.dart'; +import 'package:wyatt_ui_kit/src/components/text_inputs/widgets/label_widget.dart'; +import 'package:wyatt_ui_kit/src/components/text_inputs/widgets/text_input_wrapper.dart'; + +class TextInputScreen extends CubitScreen { + TextInputScreen({ + this.expand, + this.onError, + this.validator, + super.key, + this.suffixText, + this.prefixText, + this.prefixIcon, + this.suffixIcon, + this.label, + this.hint, + this.normalStyle, + this.focusedStyle, + this.errorStyle, + this.disableStyle, + this.magnifierConfiguration, + this.controller, + this.focusNode, + this.keyboardType, + this.textInputAction, + this.textCapitalization, + this.style, + this.strutStyle, + this.textAlign, + this.textAlignVertical, + this.textDirection, + this.autofocus, + this.obscuringCharacter, + this.obscureText, + this.autocorrect, + this.smartDashesType, + this.smartQuotesType, + this.enableSuggestions, + this.maxLines, + this.minLines, + this.expands, + this.readOnly, + this.showCursor, + this.maxLength, + this.maxLengthEnforcement, + this.onChanged, + this.onEditingComplete, + this.onSubmitted, + this.onAppPrivateCommand, + this.inputFormatters, + this.enabled, + this.cursorWidth, + this.cursorHeight, + this.cursorRadius, + this.cursorColor, + this.selectionHeightStyle, + this.selectionWidthStyle, + this.keyboardAppearance, + this.scrollPadding, + this.enableInteractiveSelection, + this.selectionControls, + this.dragStartBehavior, + this.onTap, + this.onTapOutside, + this.mouseCursor, + this.scrollPhysics, + this.scrollController, + this.autofillHints, + this.clipBehavior, + this.restorationId, + this.scribbleEnabled, + this.enableIMEPersonalizedLearning, + this.contextMenuBuilder, + this.spellCheckConfiguration, + }); + + final TextMagnifierConfiguration? magnifierConfiguration; + final TextEditingController? controller; + final FocusNode? focusNode; + final TextInputType? keyboardType; + final TextInputAction? textInputAction; + final TextCapitalization? textCapitalization; + final TextStyle? style; + final StrutStyle? strutStyle; + final TextAlign? textAlign; + final TextAlignVertical? textAlignVertical; + final TextDirection? textDirection; + final bool? autofocus; + final String? obscuringCharacter; + final bool? obscureText; + final bool? autocorrect; + final SmartDashesType? smartDashesType; + final SmartQuotesType? smartQuotesType; + final bool? enableSuggestions; + final int? maxLines; + final int? minLines; + final bool? expands; + final bool? readOnly; + final bool? showCursor; + final int? maxLength; + final MaxLengthEnforcement? maxLengthEnforcement; + final ValueChanged? onChanged; + final VoidCallback? onEditingComplete; + final ValueChanged? onSubmitted; + final AppPrivateCommandCallback? onAppPrivateCommand; + final List? inputFormatters; + final double? cursorWidth; + final double? cursorHeight; + final Radius? cursorRadius; + final Color? cursorColor; + final BoxHeightStyle? selectionHeightStyle; + final BoxWidthStyle? selectionWidthStyle; + final Brightness? keyboardAppearance; + final EdgeInsets? scrollPadding; + final bool? enableInteractiveSelection; + final TextSelectionControls? selectionControls; + final DragStartBehavior? dragStartBehavior; + final GestureTapCallback? onTap; + final TapRegionCallback? onTapOutside; + final MouseCursor? mouseCursor; + final ScrollPhysics? scrollPhysics; + final ScrollController? scrollController; + final Iterable? autofillHints; + final Clip? clipBehavior; + final String? restorationId; + final bool? scribbleEnabled; + final bool? enableIMEPersonalizedLearning; + final EditableTextContextMenuBuilder? contextMenuBuilder; + final SpellCheckConfiguration? spellCheckConfiguration; + + final bool Function(String)? validator; + final String? Function(String)? onError; + + final TextInputStyle? normalStyle; + final TextInputStyle? focusedStyle; + final TextInputStyle? errorStyle; + final TextInputStyle? disableStyle; + + final TextWrapper? label; + final TextWrapper? hint; + final ValueNotifier? enabled; + + final bool? expand; + + final TextWrapper? prefixText; + final Icon? prefixIcon; + final Icon? suffixIcon; + final TextWrapper? suffixText; + + @override + TextInputCubit create(BuildContext context) => TextInputCubit(); + + @override + TextInputCubit init(BuildContext context, TextInputCubit bloc) { + enabled?.addListener(() { + if (enabled?.value ?? false) { + bloc.enable(); + } else { + bloc.disable(); + } + }); + return bloc; + } + + final _focusNode = FocusNode(); + final _controller = TextEditingController(); + + final _notOutilinedBorder = const OutlineInputBorder( + borderSide: BorderSide(color: Colors.transparent), + ); + + TextInputStyle _resolve(BuildContext context, TextInputState state) { + final resolver = TextInputThemeResolver( + customStyleFn: (context, extensionValue, {extra}) { + TextInputStyle? textInputStyle; + switch (extra?.controlState) { + case ControlState.focused: + textInputStyle = focusedStyle; + break; + case ControlState.disabled: + textInputStyle = disableStyle; + break; + case ControlState.normal: + textInputStyle = normalStyle; + break; + case ControlState.hovered: + break; + case ControlState.tapped: + break; + case null: + break; + } + + TextInputStyle? style; + switch (extra?.statusState) { + case StatusState.error: + style = errorStyle; + break; + case StatusState.initial: + break; + case StatusState.success: + break; + case StatusState.loading: + break; + case null: + break; + } + + return TextInputStyle.merge( + extensionValue, + TextInputStyle.merge(textInputStyle, style), + ); + }, + ); + + return resolver.negotiate(context, extra: state); + } + + bool _wrapperExpanded(TextInputState state) { + final fn = focusNode ?? _focusNode; + final tec = controller ?? _controller; + if (fn.hasFocus && label != null) { + return true; + } else if (tec.value.text.isNotEmpty && label != null) { + return true; + } else if (state.statusState == StatusState.error && + (state.statusMessage?.isNotEmpty ?? false)) { + return true; + } + return false; + } + + @override + Widget onBuild(BuildContext context, TextInputState state) { + final style = _resolve(context, state); + return Focus( + onFocusChange: (hasFocus) { + if (hasFocus) { + bloc(context).onFocus(); + } else { + bloc(context).onUnfocus(); + } + }, + child: AnimatedContainer( + duration: const Duration(milliseconds: 600), + decoration: BoxDecoration( + boxShadow: style.boxShadow != null ? [style.boxShadow!] : null, + gradient: style.backgroundColors?.isGradient ?? false + ? LinearGradient(colors: style.backgroundColors!.colors) + : null, + color: style.backgroundColors?.isColor ?? false + ? style.backgroundColors?.color + : null, + borderRadius: style.radius ?? BorderRadius.circular(4), + border: (style.borderColors?.isGradient ?? false) || + (style.borderColors?.isColor ?? false) + ? Border.all( + width: 1.5, + color: (style.borderColors?.isGradient ?? false) + ? style.borderColors!.colors.first + : (style.borderColors?.isColor ?? false) + ? style.borderColors!.color + : Colors.transparent, + ) + : null, + ), + child: TextInputWrapper( + expand: expand ?? true, + expanded: _wrapperExpanded(state), + child: TextField( + onTap: onTap, + onChanged: (value) { + onChanged?.call(value); + if (validator?.call(value) ?? false) { + bloc(context).onInvalid(onError?.call(value)); + } else { + bloc(context).onSuccess(); + } + }, + onTapOutside: onTapOutside, + controller: controller ?? _controller, + focusNode: focusNode ?? _focusNode, + textAlignVertical: textAlignVertical ?? TextAlignVertical.top, + style: style.inputStyle ?? this.style, + decoration: InputDecoration( + focusedErrorBorder: _notOutilinedBorder, + focusedBorder: _notOutilinedBorder, + errorBorder: _notOutilinedBorder, + disabledBorder: _notOutilinedBorder, + enabledBorder: _notOutilinedBorder, + border: _notOutilinedBorder, + isDense: true, + iconColor: style.iconColor, + alignLabelWithHint: true, + label: (state.statusState == StatusState.error && + (state.statusMessage?.isNotEmpty ?? false)) || + label != null + ? LabelWidget( + focusNode: focusNode ?? _focusNode, + label: (state.statusState == StatusState.error && + (state.statusMessage?.isNotEmpty ?? false)) + ? state.statusMessage?.wrap() + : label, + labelStyle: style.labelStyle, + ) + : null, + hintText: hint?.text, + hintStyle: hint?.style, + prefixIcon: prefixIcon, + prefixText: prefixText?.text, + prefixStyle: prefixText?.style, + prefixIconColor: style.prefixIconColor, + suffixIcon: suffixIcon, + suffixText: suffixText?.text, + suffixStyle: suffixText?.style, + suffixIconColor: style.suffixIconColor, + enabled: state.controlState != ControlState.disabled, + ), + keyboardType: keyboardType, + smartDashesType: smartDashesType, + smartQuotesType: smartQuotesType, + enableInteractiveSelection: enableInteractiveSelection, + textInputAction: textInputAction, + textCapitalization: textCapitalization ?? TextCapitalization.none, + strutStyle: strutStyle, + textAlign: textAlign ?? TextAlign.start, + textDirection: textDirection, + readOnly: readOnly ?? false, + showCursor: showCursor, + autofocus: autofocus ?? false, + obscuringCharacter: obscuringCharacter ?? '*', + obscureText: obscureText ?? false, + autocorrect: autocorrect ?? true, + enableSuggestions: enableSuggestions ?? true, + maxLines: maxLines ?? 1, + minLines: minLines, + expands: expands ?? false, + maxLength: maxLength, + maxLengthEnforcement: maxLengthEnforcement, + onEditingComplete: onEditingComplete, + onSubmitted: onSubmitted, + onAppPrivateCommand: onAppPrivateCommand, + inputFormatters: inputFormatters, + enabled: state.controlState != ControlState.disabled, + cursorWidth: cursorWidth ?? 2.0, + cursorHeight: cursorHeight, + cursorRadius: cursorRadius, + cursorColor: cursorColor, + selectionHeightStyle: selectionHeightStyle ?? BoxHeightStyle.tight, + selectionWidthStyle: selectionWidthStyle ?? BoxWidthStyle.tight, + keyboardAppearance: keyboardAppearance, + scrollPadding: scrollPadding ?? const EdgeInsets.all(20), + dragStartBehavior: dragStartBehavior ?? DragStartBehavior.start, + selectionControls: selectionControls, + mouseCursor: mouseCursor, + scrollController: scrollController, + scrollPhysics: scrollPhysics, + autofillHints: autofillHints, + clipBehavior: clipBehavior ?? Clip.hardEdge, + restorationId: restorationId, + scribbleEnabled: scribbleEnabled ?? true, + enableIMEPersonalizedLearning: + enableIMEPersonalizedLearning ?? true, + contextMenuBuilder: contextMenuBuilder, + spellCheckConfiguration: spellCheckConfiguration, + magnifierConfiguration: magnifierConfiguration, + ), + ), + ), + ); + } +} diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart new file mode 100644 index 00000000..b774c720 --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart @@ -0,0 +1,172 @@ +// 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:flutter/material.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; +import 'package:wyatt_ui_kit/src/components/text_inputs/cubit/text_input_cubit.dart'; +import 'package:wyatt_ui_kit/src/core/core.dart'; +import 'package:wyatt_ui_kit/src/domain/text_input_theme_extension.dart'; + +class TextInputThemeResolver extends ThemeResolver { + const TextInputThemeResolver({ + required this.customStyleFn, + }); + + @override + final TextInputStyle? Function( + BuildContext context, + TextInputStyle extensionValue, { + TextInputState? extra, + }) customStyleFn; + + @override + TextInputStyle computeDefaultValue( + BuildContext context, { + TextInputState? extra, + }) { + TextStyle? labelStyle = context.textTheme.labelLarge + ?.copyWith(color: Theme.of(context).unselectedWidgetColor); + + TextStyle? hintStyle = context.textTheme.labelLarge; + TextStyle? prefixStyle = context.textTheme.bodyMedium; + TextStyle? suffixStyle = context.textTheme.bodyMedium; + TextStyle? inputStyle = context.textTheme.bodyMedium; + + Color? iconColor = context.colorScheme.inversePrimary; + Color? prefixIconColor = Theme.of(context).unselectedWidgetColor; + Color? suffixIconColor = Theme.of(context).unselectedWidgetColor; + + MultiColor? borderColors = + MultiColor.single(Theme.of(context).unselectedWidgetColor); + + MultiColor? backgroundColors; + BoxShadow? boxShadow; + + final BorderRadiusGeometry radius = BorderRadius.circular(4); + + switch (extra?.controlState) { + case ControlState.disabled: + labelStyle = + labelStyle?.copyWith(color: Theme.of(context).disabledColor); + hintStyle = hintStyle?.copyWith(color: Theme.of(context).disabledColor); + prefixStyle = + prefixStyle?.copyWith(color: Theme.of(context).disabledColor); + suffixStyle = + suffixStyle?.copyWith(color: Theme.of(context).disabledColor); + inputStyle = + inputStyle?.copyWith(color: Theme.of(context).disabledColor); + borderColors = MultiColor.single(Theme.of(context).disabledColor); + prefixIconColor = Theme.of(context).disabledColor; + suffixIconColor = Theme.of(context).disabledColor; + + break; + + case ControlState.focused: + prefixIconColor = context.colorScheme.primary; + suffixIconColor = context.colorScheme.primary; + iconColor = context.colorScheme.primary; + borderColors = MultiColor.single(context.colorScheme.primary); + labelStyle = labelStyle?.copyWith(color: context.colorScheme.primary); + break; + case ControlState.hovered: + break; + case ControlState.tapped: + break; + case ControlState.normal: + break; + case null: + break; + } + + switch (extra?.statusState) { + case StatusState.error: + labelStyle = context.textTheme.labelLarge + ?.copyWith(color: context.colorScheme.error); + borderColors = MultiColor.single(context.colorScheme.error); + break; + case StatusState.initial: + break; + case StatusState.success: + break; + case StatusState.loading: + break; + case null: + break; + } + return TextInputStyle( + labelStyle: labelStyle, + hintStyle: hintStyle, + iconColor: iconColor, + prefixIconColor: prefixIconColor, + prefixStyle: prefixStyle, + suffixStyle: suffixStyle, + suffixIconColor: suffixIconColor, + backgroundColors: backgroundColors, + borderColors: borderColors, + boxShadow: boxShadow, + radius: radius, + inputStyle: inputStyle, + ); + } + + @override + TextInputStyle? computeExtensionValueFn( + BuildContext context, + TextInputStyle defaultValue, + TextInputThemeExtension themeExtension, { + TextInputState? extra, + }) { + TextInputStyle? textInputStyle; + switch (extra?.controlState) { + case ControlState.focused: + textInputStyle = themeExtension.focusedStyle; + break; + case ControlState.disabled: + textInputStyle = themeExtension.disableStyle; + break; + case ControlState.normal: + textInputStyle = themeExtension.normalStyle; + break; + case ControlState.hovered: + break; + case ControlState.tapped: + break; + case null: + break; + } + + TextInputStyle? style; + switch (extra?.statusState) { + case StatusState.error: + style = themeExtension.errorStyle; + break; + case StatusState.initial: + break; + case StatusState.success: + break; + case StatusState.loading: + break; + case null: + break; + } + + return TextInputStyle.merge( + defaultValue, + TextInputStyle.merge(textInputStyle, style), + ); + } +} diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/widgets/label_widget.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/widgets/label_widget.dart new file mode 100644 index 00000000..0312c62e --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/widgets/label_widget.dart @@ -0,0 +1,37 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// super 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. +// +// super 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 super program. If not, see . + +import 'package:flutter/material.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; + +class LabelWidget extends StatelessWidget { + const LabelWidget({ + required this.label, + required this.focusNode, + required this.labelStyle, + super.key, + }); + + final TextWrapper? label; + final FocusNode focusNode; + final TextStyle? labelStyle; + + @override + Widget build(BuildContext context) => Text( + label?.text ?? '', + style: labelStyle, + ); +} diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/widgets/text_input_wrapper.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/widgets/text_input_wrapper.dart new file mode 100644 index 00000000..ba868365 --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/widgets/text_input_wrapper.dart @@ -0,0 +1,60 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// super 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. +// +// super 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 super program. If not, see . + +import 'package:flutter/material.dart'; + +const _defaultPadding = 7.5; +const _paddingAnimationDuration = Duration(milliseconds: 200); + +class TextInputWrapper extends StatelessWidget { + const TextInputWrapper({ + required this.expand, + required this.expanded, + required this.child, + super.key, + }); + final bool expand; + final bool expanded; + final Widget child; + + double _top() { + if (expanded) { + return 2 * _defaultPadding; + } else if (!expand) { + return _defaultPadding; + } + return 0; + } + + double _bottom() { + if (expanded) { + return 0; + } else if (!expand) { + return _defaultPadding; + } + return 0; + } + + @override + Widget build(BuildContext context) => AnimatedPadding( + duration: _paddingAnimationDuration, + padding: EdgeInsets.only( + top: _top(), + bottom: _bottom(), + ), + child: child, + ); +} diff --git a/packages/wyatt_ui_kit/lib/src/core/extensions/theme_extensions.dart b/packages/wyatt_ui_kit/lib/src/core/extensions/theme_extensions.dart index 5e39a69c..c874454a 100644 --- a/packages/wyatt_ui_kit/lib/src/core/extensions/theme_extensions.dart +++ b/packages/wyatt_ui_kit/lib/src/core/extensions/theme_extensions.dart @@ -21,4 +21,6 @@ extension BuildContextThemeExtension on BuildContext { TextTheme get textTheme => Theme.of(this).textTheme; ColorScheme get colorScheme => Theme.of(this).colorScheme; ButtonThemeData get buttonTheme => Theme.of(this).buttonTheme; + InputDecorationTheme get inputDecorationTheme => + Theme.of(this).inputDecorationTheme; } diff --git a/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart b/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart new file mode 100644 index 00000000..f5164d65 --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart @@ -0,0 +1,33 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// super 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. +// +// super 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 super program. If not, see . + +class ThemeHelper { + static T? getThemeElement( + List? styles, { + required T? Function(P?)? transform, + required T? defaultValue, + bool? Function(P?)? valueValidator, + }) { + if (styles?.isNotEmpty ?? false) { + for (final element in styles!) { + if (valueValidator?.call(element) ?? false) { + return transform?.call(element); + } + } + } + return defaultValue; + } +} diff --git a/packages/wyatt_ui_kit/lib/src/domain/domain.dart b/packages/wyatt_ui_kit/lib/src/domain/domain.dart index 51fa4377..7456e08c 100644 --- a/packages/wyatt_ui_kit/lib/src/domain/domain.dart +++ b/packages/wyatt_ui_kit/lib/src/domain/domain.dart @@ -16,5 +16,9 @@ export './button_theme_extension/button_theme_extension.dart'; export './card_theme_extension.dart'; +<<<<<<< HEAD export './loader_theme_extension.dart'; export './rich_text_builder_theme_extension.dart'; +======= +export 'text_input_theme_extension.dart'; +>>>>>>> 548df1c (feat(ui_kit): implemement text inputs (#138)) diff --git a/packages/wyatt_ui_kit/lib/src/domain/input_text_theme_extension.dart b/packages/wyatt_ui_kit/lib/src/domain/text_input_theme_extension.dart similarity index 67% rename from packages/wyatt_ui_kit/lib/src/domain/input_text_theme_extension.dart rename to packages/wyatt_ui_kit/lib/src/domain/text_input_theme_extension.dart index d71340fc..8fe456bb 100644 --- a/packages/wyatt_ui_kit/lib/src/domain/input_text_theme_extension.dart +++ b/packages/wyatt_ui_kit/lib/src/domain/text_input_theme_extension.dart @@ -17,20 +17,17 @@ import 'package:flutter/material.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; -abstract class InputTexThemetExtension - extends ThemeExtension { - InputTexThemetExtension({ - this.backgroundColors, - this.borderColors, - this.floatingLabelTextStyle, - this.inputStyle, +abstract class TextInputThemeExtension + extends ThemeExtension { + const TextInputThemeExtension({ + this.normalStyle, + this.focusedStyle, + this.errorStyle, + this.disableStyle, }); - // Colors: - final MultiColor? backgroundColors; - final MultiColor? borderColors; - - // TextStyles: - final TextStyle? floatingLabelTextStyle; - final TextStyle? inputStyle; + final TextInputStyle? normalStyle; + final TextInputStyle? focusedStyle; + final TextInputStyle? errorStyle; + final TextInputStyle? disableStyle; } -- 2.47.2 From b57500b85437382befd5be66818e91c51e66ad12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 08:22:38 +0100 Subject: [PATCH 08/25] feat(ui_kit): update example (#138) --- packages/wyatt_ui_kit/example/lib/home.dart | 2 + .../example/lib/text_input/text_inputs.dart | 140 ++++++++++++++ .../example/lib/theme/text_input_theme.dart | 181 ++++++++++++++++++ .../example/lib/theme/themes.dart | 3 + 4 files changed, 326 insertions(+) create mode 100644 packages/wyatt_ui_kit/example/lib/text_input/text_inputs.dart create mode 100644 packages/wyatt_ui_kit/example/lib/theme/text_input_theme.dart diff --git a/packages/wyatt_ui_kit/example/lib/home.dart b/packages/wyatt_ui_kit/example/lib/home.dart index cac6c236..9d772a61 100644 --- a/packages/wyatt_ui_kit/example/lib/home.dart +++ b/packages/wyatt_ui_kit/example/lib/home.dart @@ -6,6 +6,7 @@ import 'package:wyatt_ui_kit_example/cards/cards.dart'; import 'package:wyatt_ui_kit_example/demo_page.dart'; import 'package:wyatt_ui_kit_example/loaders/loaders.dart'; import 'package:wyatt_ui_kit_example/rich_text_builders/rich_text_builders.dart'; +import 'package:wyatt_ui_kit_example/text_input/text_inputs.dart'; import 'package:wyatt_ui_kit_example/theme/themes.dart'; const String title = 'Wyatt UIKit Example'; @@ -26,6 +27,7 @@ class _HomeState extends State { Buttons(), Loaders(), RichTextBuilders(), + TextInputs(), ]; int currentIndex = 0; diff --git a/packages/wyatt_ui_kit/example/lib/text_input/text_inputs.dart b/packages/wyatt_ui_kit/example/lib/text_input/text_inputs.dart new file mode 100644 index 00000000..7d568abd --- /dev/null +++ b/packages/wyatt_ui_kit/example/lib/text_input/text_inputs.dart @@ -0,0 +1,140 @@ +import 'package:flutter/material.dart'; +import 'package:gap/gap.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; +import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; +import 'package:wyatt_ui_kit_example/demo_page.dart'; + +class TextInputs extends DemoPage { + const TextInputs({super.key}); + + @override + Widget build(BuildContext context) => const TextInputsCore(); + + @override + String get title => 'Text Inputs'; +} + +class TextInputsCore extends StatefulWidget { + const TextInputsCore({super.key}); + + @override + State createState() => _TextInputsCoreState(); +} + +class _TextInputsCoreState extends State { + final _formKey = GlobalKey(); + final _controller = TextEditingController(); + final _focusNode = FocusNode(); + + final _formKey2 = GlobalKey(); + final _controller2 = TextEditingController(); + final _focusNode2 = FocusNode(); + + final _formKey3 = GlobalKey(); + final _controller3 = TextEditingController(); + final _focusNode3 = FocusNode(); + + final _formKey4 = GlobalKey(); + final _controller4 = TextEditingController(); + final _focusNode4 = FocusNode(); + + final _formKey5 = GlobalKey(); + final _controller5 = TextEditingController(); + final _focusNode5 = FocusNode(); + + final _formKey6 = GlobalKey(); + final _controller6 = TextEditingController(); + final _focusNode6 = FocusNode(); + + final ValueNotifier _enable = ValueNotifier(true); + + @override + void initState() { + super.initState(); + Future.delayed(const Duration(milliseconds: 500), () { + setState(() { + _enable.value = false; + }); + }); + } + + @override + Widget build(BuildContext context) => Form( + child: ListView( + cacheExtent: 1000, + children: [ + const Gap(20), + Align( + child: Text( + 'Text inputs', + style: Theme.of(context).textTheme.titleLarge, + ), + ), + const Gap(20), + TextInput( + key: _formKey6, + controller: _controller6, + focusNode: _focusNode6, + label: 'Nom / Prénom'.wrap(), + onError: (value) => 'Erreur : ${value.length} > 5.', + validator: (value) => value.length > 5, + ), + const Gap(20), + TextInput( + key: _formKey, + enabled: _enable, + controller: _controller, + focusNode: _focusNode, + label: 'Nom / Prénom'.wrap(), + onError: (value) => 'Erreur : ${value.length} > 5.', + validator: (value) => value.length > 5, + ), + const Gap(20), + TextInput( + key: _formKey2, + controller: _controller2, + focusNode: _focusNode2, + maxLines: 3, + onError: (value) => 'Erreur : ${value.length} > 5.', + validator: (value) => value.length > 5, + onChanged: (value) {}, + ), + const Gap(20), + TextInput( + key: _formKey3, + controller: _controller3, + focusNode: _focusNode3, + expand: false, + label: 'Nom / Prénom'.wrap(), + onError: (value) => 'Erreur : ${value.length} > 5.', + validator: (value) => value.length > 5, + onChanged: (value) {}, + ), + const Gap(20), + TextInput( + key: _formKey4, + expand: false, + controller: _controller4, + focusNode: _focusNode4, + label: 'Nom / Prénom'.wrap(), + maxLines: 3, + onError: (value) => 'Erreur : ${value.length} > 5.', + validator: (value) => value.length > 5, + onChanged: (value) {}, + ), + const Gap(20), + TextInput( + key: _formKey5, + prefixIcon: const Icon(Icons.architecture), + suffixIcon: const Icon(Icons.architecture), + controller: _controller5, + focusNode: _focusNode5, + label: 'Nom / Prénom'.wrap(), + onError: (value) => 'Erreur : ${value.length} > 5.', + validator: (value) => value.length > 5, + ), + const Gap(20), + ], + ), + ); +} diff --git a/packages/wyatt_ui_kit/example/lib/theme/text_input_theme.dart b/packages/wyatt_ui_kit/example/lib/theme/text_input_theme.dart new file mode 100644 index 00000000..93e583f4 --- /dev/null +++ b/packages/wyatt_ui_kit/example/lib/theme/text_input_theme.dart @@ -0,0 +1,181 @@ +// 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:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; +import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; + +class TextInputTheme extends TextInputThemeExtension { + const TextInputTheme({ + super.normalStyle, + super.focusedStyle, + super.disableStyle, + super.errorStyle, + }); + + factory TextInputTheme.light() => TextInputTheme( + normalStyle: TextInputStyle( + radius: BorderRadius.circular(12), + borderColors: const MultiColor([ + Color.fromRGBO(221, 224, 227, 1), + Color.fromRGBO(202, 204, 212, 1), + ]), + labelStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(55, 65, 81, 1), + ), + inputStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(55, 65, 81, 1), + ), + ), + focusedStyle: TextInputStyle( + radius: BorderRadius.circular(12), + borderColors: const MultiColor([ + Color.fromRGBO(60, 125, 251, 1), + Color.fromRGBO(68, 109, 244, 1), + ]), + labelStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(55, 65, 81, 1), + ), + inputStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(55, 65, 81, 1), + ), + ), + errorStyle: TextInputStyle( + radius: BorderRadius.circular(12), + borderColors: const MultiColor([ + Color.fromRGBO(251, 94, 60, 1), + Color.fromRGBO(244, 68, 100, 1), + ]), + labelStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(244, 68, 100, 1), + ), + inputStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(55, 65, 81, 1), + ), + ), + disableStyle: TextInputStyle( + radius: BorderRadius.circular(12), + borderColors: + const MultiColor.single(Color.fromRGBO(229, 231, 235, 1)), + labelStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(156, 163, 175, 1), + ), + inputStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(156, 163, 175, 1), + ), + ), + ); + + factory TextInputTheme.dark() => TextInputTheme( + normalStyle: TextInputStyle( + radius: BorderRadius.circular(12), + borderColors: const MultiColor.single( + Color.fromRGBO(96, 101, 106, 1), + ), + labelStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(204, 204, 204, 1), + ), + inputStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(255, 255, 255, 1), + ), + ), + focusedStyle: TextInputStyle( + radius: BorderRadius.circular(12), + borderColors: const MultiColor([ + Color.fromRGBO(60, 125, 251, 1), + Color.fromRGBO(68, 109, 244, 1), + ]), + labelStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(204, 204, 204, 1), + ), + inputStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(255, 255, 255, 1), + ), + ), + errorStyle: TextInputStyle( + radius: BorderRadius.circular(12), + borderColors: const MultiColor([ + Color.fromRGBO(251, 94, 60, 1), + Color.fromRGBO(244, 68, 100, 1), + ]), + labelStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(244, 68, 100, 1), + ), + inputStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(255, 255, 255, 1), + ), + ), + disableStyle: TextInputStyle( + radius: BorderRadius.circular(12), + borderColors: const MultiColor.single( + Color.fromRGBO(96, 101, 106, 1), + ), + labelStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(96, 101, 106, 1), + ), + inputStyle: GoogleFonts.montserrat( + fontWeight: FontWeight.w300, + color: const Color.fromRGBO(255, 255, 255, 1), + ), + ), + ); + + @override + ThemeExtension lerp( + covariant ThemeExtension? other, + double t, + ) { + if (other is! TextInputTheme) { + return this; + } + return TextInputTheme( + normalStyle: TextInputStyle.lerp(normalStyle, other.normalStyle, t), + focusedStyle: TextInputStyle.lerp(focusedStyle, other.focusedStyle, t), + disableStyle: TextInputStyle.lerp(disableStyle, other.disableStyle, t), + errorStyle: TextInputStyle.lerp(errorStyle, other.errorStyle, t), + ); + } + + @override + ThemeExtension copyWith({ + TextInputStyle? normalStyle, + TextInputStyle? focusedStyle, + TextInputStyle? disableStyle, + TextInputStyle? errorStyle, + }) => + TextInputTheme( + normalStyle: normalStyle ?? this.normalStyle, + focusedStyle: focusedStyle ?? this.focusedStyle, + disableStyle: disableStyle ?? this.disableStyle, + errorStyle: errorStyle ?? this.errorStyle, + ); +} diff --git a/packages/wyatt_ui_kit/example/lib/theme/themes.dart b/packages/wyatt_ui_kit/example/lib/theme/themes.dart index 63ecea53..6bb52867 100644 --- a/packages/wyatt_ui_kit/example/lib/theme/themes.dart +++ b/packages/wyatt_ui_kit/example/lib/theme/themes.dart @@ -24,6 +24,7 @@ import 'package:wyatt_ui_kit_example/theme/loader_theme.dart'; import 'package:wyatt_ui_kit_example/theme/rich_text_builder_theme.dart'; import 'package:wyatt_ui_kit_example/theme/simple_icon_button_theme.dart'; import 'package:wyatt_ui_kit_example/theme/symbol_button_theme.dart'; +import 'package:wyatt_ui_kit_example/theme/text_input_theme.dart'; /// Easely switch between Material and Studio themes. abstract class Themes { @@ -90,6 +91,7 @@ abstract class Themes { LoaderTheme.light(), // Rich Text RichTextBuilderTheme.light(), + TextInputTheme.light(), ], ); @@ -121,6 +123,7 @@ abstract class Themes { LoaderTheme.dark(), // Rich Text RichTextBuilderTheme.dark(), + TextInputTheme.dark(), ], ); } -- 2.47.2 From 9b9339cb564db64e6d8dcae563bdb0e41df54999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 08:49:52 +0100 Subject: [PATCH 09/25] chore(ui_components): add copywith deps --- packages/wyatt_ui_components/pubspec.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/wyatt_ui_components/pubspec.yaml b/packages/wyatt_ui_components/pubspec.yaml index 80e5e707..395554ea 100644 --- a/packages/wyatt_ui_components/pubspec.yaml +++ b/packages/wyatt_ui_components/pubspec.yaml @@ -10,6 +10,7 @@ environment: dependencies: flutter: { sdk: flutter } + copy_with_extension: ^5.0.0 wyatt_component_copy_with_extension: git: url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git @@ -17,6 +18,7 @@ dependencies: dev_dependencies: build_runner: ^2.3.3 + copy_with_extension_gen: ^5.0.0 flutter_test: { sdk: flutter } wyatt_analysis: hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub -- 2.47.2 From b6d22002ee2585ccf912b45f833422ba1c98b8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 08:52:18 +0100 Subject: [PATCH 10/25] fix(ui_kit): fix export theme file --- packages/wyatt_ui_kit/lib/src/domain/domain.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/wyatt_ui_kit/lib/src/domain/domain.dart b/packages/wyatt_ui_kit/lib/src/domain/domain.dart index 7456e08c..6cf19139 100644 --- a/packages/wyatt_ui_kit/lib/src/domain/domain.dart +++ b/packages/wyatt_ui_kit/lib/src/domain/domain.dart @@ -16,9 +16,6 @@ export './button_theme_extension/button_theme_extension.dart'; export './card_theme_extension.dart'; -<<<<<<< HEAD export './loader_theme_extension.dart'; export './rich_text_builder_theme_extension.dart'; -======= -export 'text_input_theme_extension.dart'; ->>>>>>> 548df1c (feat(ui_kit): implemement text inputs (#138)) +export './text_input_theme_extension.dart'; -- 2.47.2 From 8ed8a71c7c2ddc97d44a764c48ce63697ad7f7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 08:53:38 +0100 Subject: [PATCH 11/25] fix(ui_kit): fix conflicts in card component after rebase --- .../lib/src/components/cards/widgets/card_wrapper.dart | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart index 736c0387..46a72582 100644 --- a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart +++ b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart @@ -112,7 +112,8 @@ class _CardWrapperState extends State { extensionCardColor.backgroundColors != null && extensionCardColor.backgroundColors!.isGradient) { return LinearGradient( - colors: extensionCardColor.backgroundColors!.colors,); + colors: extensionCardColor.backgroundColors!.colors, + ); } } return null; @@ -151,15 +152,9 @@ class _CardWrapperState extends State { final extensionCardColor = Theme.of(context).extension(); if (extensionCardColor != null && -<<<<<<< HEAD extensionCardColor.borderColors != null) { if (extensionCardColor.borderColors!.isGradient) { - return GradientBoxBorder( -======= - extensionCardColor.borderColor != null) { - if (extensionCardColor.borderColor!.length >= 2) { return CustomGradientBoxBorder( ->>>>>>> 548df1c (feat(ui_kit): implemement text inputs (#138)) gradient: LinearGradient( colors: extensionCardColor.borderColors!.colors, ), -- 2.47.2 From 4030511f4a4d1be6081f38717613ace06f096a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 09:54:19 +0100 Subject: [PATCH 12/25] fix(ui_components-ui_kit): fix, clean and unify logic and code after rebase --- .../lib/src/core/utils/theme_resolver.dart | 22 ++- .../buttons/file_selection_button_style.dart | 34 +--- .../file_selection_button_style.g.dart | 152 ++++++++++++++++++ .../entities/buttons/flat_button_style.dart | 29 +--- .../entities/buttons/flat_button_style.g.dart | 137 ++++++++++++++++ .../buttons/simple_icon_button_style.dart | 29 +--- .../buttons/simple_icon_button_style.g.dart | 141 ++++++++++++++++ .../entities/buttons/symbol_button_style.dart | 31 +--- .../buttons/symbol_button_style.g.dart | 150 +++++++++++++++++ .../lib/src/domain/entities/loader_style.dart | 17 +- .../src/domain/entities/loader_style.g.dart | 67 ++++++++ .../rich_text_builder_style.dart | 17 +- .../rich_text_builder_style.g.dart | 71 ++++++++ .../text_inputs/text_input_style.dart | 6 +- .../lib/src/domain/entities/theme_style.dart | 8 +- .../file_selection_button_screen.dart | 2 +- .../file_selection_button_theme_resolver.dart | 6 +- .../flat_button/flat_button_screen.dart | 2 +- .../flat_button_theme_resolver.dart | 4 +- .../simple_icon_button_theme_resolver.dart | 4 +- .../simple_icon_screen.dart | 2 +- .../symbol_button/symbol_button_screen.dart | 2 +- .../symbol_button_theme_resolver.dart | 6 +- .../lib/src/components/loader/loader.dart | 10 -- .../loader/loader_theme_resolver.dart | 17 +- .../rich_text_builder/rich_text_builder.dart | 10 -- .../rich_text_builder_theme_resolver.dart | 18 ++- .../text_inputs/text_input_screen.dart | 7 +- .../text_input_theme_resolver.dart | 9 +- 29 files changed, 787 insertions(+), 223 deletions(-) create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.g.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.g.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.g.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.g.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/loader_style.g.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.g.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 c77e588b..4626fb50 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 @@ -35,59 +35,55 @@ abstract class ThemeResolver, T, E> { /// {@macro theme_resolver} const ThemeResolver(); - S? Function(BuildContext context, S extensionValue, {E? extra}) - get customStyleFn; + S? Function(BuildContext context, {E? extra}) get customStyleFn; /// Compute default value from Flutter Theme or with hardcoded values. S computeDefaultValue(BuildContext context, {E? extra}); S? computeExtensionValueFn( BuildContext context, - S defaultValue, T themeExtension, { E? extra, }); /// Compute values from the extension if found S? _computeExtensionValue( - BuildContext context, - S defaultValue, { + BuildContext context, { E? extra, }) { final themeExtension = Theme.of(context).extension(); if (themeExtension != null) { return computeExtensionValueFn( context, - defaultValue, themeExtension, extra: extra, ); } - return defaultValue; + return null; } /// Compute custom value S? _computeCustomValue( - BuildContext context, - S previousPhaseValue, { + BuildContext context, { E? extra, }) { final customStyle = customStyleFn( context, - previousPhaseValue, extra: extra, ); if (customStyle != null) { return customStyle; } - return previousPhaseValue; + return null; } /// 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; + style = + style.mergeWith(_computeExtensionValue(context, extra: extra)) ?? style; + style = + style.mergeWith(_computeCustomValue(context, extra: extra)) ?? style; return style; } } 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 75fc9a42..8585273e 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 @@ -16,10 +16,13 @@ import 'dart:ui'; +import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; +part 'file_selection_button_style.g.dart'; +@CopyWith() class FileSelectionButtonStyle extends ButtonStyle { const FileSelectionButtonStyle({ this.title, @@ -106,35 +109,4 @@ class FileSelectionButtonStyle extends ButtonStyle { @override FileSelectionButtonStyle mergeWith(FileSelectionButtonStyle? other) => FileSelectionButtonStyle.merge(this, other)!; - - @override - FileSelectionButtonStyle? lerpWith( - FileSelectionButtonStyle? other, - double t, - ) => - FileSelectionButtonStyle.lerp(this, other, t); - - @override - FileSelectionButtonStyle copyWith({ - TextStyle? title, - TextStyle? subTitle, - BorderRadiusGeometry? radius, - EdgeInsetsGeometry? padding, - MultiColor? foregroundColors, - MultiColor? backgroundColors, - MultiColor? borderColors, - double? stroke, - BoxShadow? shadow, - }) => - FileSelectionButtonStyle( - title: title ?? this.title, - subTitle: subTitle ?? this.subTitle, - radius: radius ?? this.radius, - padding: padding ?? this.padding, - foregroundColors: foregroundColors ?? this.foregroundColors, - backgroundColors: backgroundColors ?? this.backgroundColors, - borderColors: borderColors ?? this.borderColors, - stroke: stroke ?? this.stroke, - shadow: shadow ?? this.shadow, - ); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.g.dart new file mode 100644 index 00000000..6576a261 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.g.dart @@ -0,0 +1,152 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'file_selection_button_style.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$FileSelectionButtonStyleCWProxy { + FileSelectionButtonStyle title(TextStyle? title); + + FileSelectionButtonStyle subTitle(TextStyle? subTitle); + + FileSelectionButtonStyle radius(BorderRadiusGeometry? radius); + + FileSelectionButtonStyle padding(EdgeInsetsGeometry? padding); + + FileSelectionButtonStyle foregroundColors(MultiColor? foregroundColors); + + FileSelectionButtonStyle backgroundColors(MultiColor? backgroundColors); + + FileSelectionButtonStyle borderColors(MultiColor? borderColors); + + FileSelectionButtonStyle stroke(double? stroke); + + FileSelectionButtonStyle shadow(BoxShadow? shadow); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FileSelectionButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// FileSelectionButtonStyle(...).copyWith(id: 12, name: "My name") + /// ```` + FileSelectionButtonStyle call({ + TextStyle? title, + TextStyle? subTitle, + BorderRadiusGeometry? radius, + EdgeInsetsGeometry? padding, + MultiColor? foregroundColors, + MultiColor? backgroundColors, + MultiColor? borderColors, + double? stroke, + BoxShadow? shadow, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfFileSelectionButtonStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfFileSelectionButtonStyle.copyWith.fieldName(...)` +class _$FileSelectionButtonStyleCWProxyImpl + implements _$FileSelectionButtonStyleCWProxy { + const _$FileSelectionButtonStyleCWProxyImpl(this._value); + + final FileSelectionButtonStyle _value; + + @override + FileSelectionButtonStyle title(TextStyle? title) => this(title: title); + + @override + FileSelectionButtonStyle subTitle(TextStyle? subTitle) => + this(subTitle: subTitle); + + @override + FileSelectionButtonStyle radius(BorderRadiusGeometry? radius) => + this(radius: radius); + + @override + FileSelectionButtonStyle padding(EdgeInsetsGeometry? padding) => + this(padding: padding); + + @override + FileSelectionButtonStyle foregroundColors(MultiColor? foregroundColors) => + this(foregroundColors: foregroundColors); + + @override + FileSelectionButtonStyle backgroundColors(MultiColor? backgroundColors) => + this(backgroundColors: backgroundColors); + + @override + FileSelectionButtonStyle borderColors(MultiColor? borderColors) => + this(borderColors: borderColors); + + @override + FileSelectionButtonStyle stroke(double? stroke) => this(stroke: stroke); + + @override + FileSelectionButtonStyle shadow(BoxShadow? shadow) => this(shadow: shadow); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FileSelectionButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// FileSelectionButtonStyle(...).copyWith(id: 12, name: "My name") + /// ```` + FileSelectionButtonStyle call({ + Object? title = const $CopyWithPlaceholder(), + Object? subTitle = const $CopyWithPlaceholder(), + Object? radius = const $CopyWithPlaceholder(), + Object? padding = const $CopyWithPlaceholder(), + Object? foregroundColors = const $CopyWithPlaceholder(), + Object? backgroundColors = const $CopyWithPlaceholder(), + Object? borderColors = const $CopyWithPlaceholder(), + Object? stroke = const $CopyWithPlaceholder(), + Object? shadow = const $CopyWithPlaceholder(), + }) { + return FileSelectionButtonStyle( + title: title == const $CopyWithPlaceholder() + ? _value.title + // ignore: cast_nullable_to_non_nullable + : title as TextStyle?, + subTitle: subTitle == const $CopyWithPlaceholder() + ? _value.subTitle + // ignore: cast_nullable_to_non_nullable + : subTitle as TextStyle?, + radius: radius == const $CopyWithPlaceholder() + ? _value.radius + // ignore: cast_nullable_to_non_nullable + : radius as BorderRadiusGeometry?, + padding: padding == const $CopyWithPlaceholder() + ? _value.padding + // ignore: cast_nullable_to_non_nullable + : padding as EdgeInsetsGeometry?, + foregroundColors: foregroundColors == const $CopyWithPlaceholder() + ? _value.foregroundColors + // ignore: cast_nullable_to_non_nullable + : foregroundColors as MultiColor?, + backgroundColors: backgroundColors == const $CopyWithPlaceholder() + ? _value.backgroundColors + // ignore: cast_nullable_to_non_nullable + : backgroundColors as MultiColor?, + borderColors: borderColors == const $CopyWithPlaceholder() + ? _value.borderColors + // ignore: cast_nullable_to_non_nullable + : borderColors as MultiColor?, + stroke: stroke == const $CopyWithPlaceholder() + ? _value.stroke + // ignore: cast_nullable_to_non_nullable + : stroke as double?, + shadow: shadow == const $CopyWithPlaceholder() + ? _value.shadow + // ignore: cast_nullable_to_non_nullable + : shadow as BoxShadow?, + ); + } +} + +extension $FileSelectionButtonStyleCopyWith on FileSelectionButtonStyle { + /// Returns a callable class that can be used as follows: `instanceOfFileSelectionButtonStyle.copyWith(...)` or like so:`instanceOfFileSelectionButtonStyle.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$FileSelectionButtonStyleCWProxy get copyWith => + _$FileSelectionButtonStyleCWProxyImpl(this); +} 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 f5476e31..676d510c 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 @@ -16,10 +16,13 @@ import 'dart:ui'; +import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; +part 'flat_button_style.g.dart'; +@CopyWith() class FlatButtonStyle extends ButtonStyle { const FlatButtonStyle({ this.label, @@ -98,30 +101,4 @@ class FlatButtonStyle extends ButtonStyle { @override FlatButtonStyle mergeWith(FlatButtonStyle? other) => FlatButtonStyle.merge(this, other)!; - - @override - FlatButtonStyle? lerpWith(FlatButtonStyle? other, double t) => - FlatButtonStyle.lerp(this, other, t); - - @override - FlatButtonStyle copyWith({ - TextStyle? label, - BorderRadiusGeometry? radius, - EdgeInsetsGeometry? padding, - MultiColor? foregroundColors, - MultiColor? backgroundColors, - MultiColor? borderColors, - double? stroke, - BoxShadow? shadow, - }) => - FlatButtonStyle( - label: label ?? this.label, - radius: radius ?? this.radius, - padding: padding ?? this.padding, - foregroundColors: foregroundColors ?? this.foregroundColors, - backgroundColors: backgroundColors ?? this.backgroundColors, - borderColors: borderColors ?? this.borderColors, - stroke: stroke ?? this.stroke, - shadow: shadow ?? this.shadow, - ); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.g.dart new file mode 100644 index 00000000..939a48e1 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.g.dart @@ -0,0 +1,137 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'flat_button_style.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$FlatButtonStyleCWProxy { + FlatButtonStyle label(TextStyle? label); + + FlatButtonStyle radius(BorderRadiusGeometry? radius); + + FlatButtonStyle padding(EdgeInsetsGeometry? padding); + + FlatButtonStyle foregroundColors(MultiColor? foregroundColors); + + FlatButtonStyle backgroundColors(MultiColor? backgroundColors); + + FlatButtonStyle borderColors(MultiColor? borderColors); + + FlatButtonStyle stroke(double? stroke); + + FlatButtonStyle shadow(BoxShadow? shadow); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FlatButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// FlatButtonStyle(...).copyWith(id: 12, name: "My name") + /// ```` + FlatButtonStyle call({ + TextStyle? label, + BorderRadiusGeometry? radius, + EdgeInsetsGeometry? padding, + MultiColor? foregroundColors, + MultiColor? backgroundColors, + MultiColor? borderColors, + double? stroke, + BoxShadow? shadow, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfFlatButtonStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfFlatButtonStyle.copyWith.fieldName(...)` +class _$FlatButtonStyleCWProxyImpl implements _$FlatButtonStyleCWProxy { + const _$FlatButtonStyleCWProxyImpl(this._value); + + final FlatButtonStyle _value; + + @override + FlatButtonStyle label(TextStyle? label) => this(label: label); + + @override + FlatButtonStyle radius(BorderRadiusGeometry? radius) => this(radius: radius); + + @override + FlatButtonStyle padding(EdgeInsetsGeometry? padding) => + this(padding: padding); + + @override + FlatButtonStyle foregroundColors(MultiColor? foregroundColors) => + this(foregroundColors: foregroundColors); + + @override + FlatButtonStyle backgroundColors(MultiColor? backgroundColors) => + this(backgroundColors: backgroundColors); + + @override + FlatButtonStyle borderColors(MultiColor? borderColors) => + this(borderColors: borderColors); + + @override + FlatButtonStyle stroke(double? stroke) => this(stroke: stroke); + + @override + FlatButtonStyle shadow(BoxShadow? shadow) => this(shadow: shadow); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FlatButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// FlatButtonStyle(...).copyWith(id: 12, name: "My name") + /// ```` + FlatButtonStyle call({ + Object? label = const $CopyWithPlaceholder(), + Object? radius = const $CopyWithPlaceholder(), + Object? padding = const $CopyWithPlaceholder(), + Object? foregroundColors = const $CopyWithPlaceholder(), + Object? backgroundColors = const $CopyWithPlaceholder(), + Object? borderColors = const $CopyWithPlaceholder(), + Object? stroke = const $CopyWithPlaceholder(), + Object? shadow = const $CopyWithPlaceholder(), + }) { + return FlatButtonStyle( + label: label == const $CopyWithPlaceholder() + ? _value.label + // ignore: cast_nullable_to_non_nullable + : label as TextStyle?, + radius: radius == const $CopyWithPlaceholder() + ? _value.radius + // ignore: cast_nullable_to_non_nullable + : radius as BorderRadiusGeometry?, + padding: padding == const $CopyWithPlaceholder() + ? _value.padding + // ignore: cast_nullable_to_non_nullable + : padding as EdgeInsetsGeometry?, + foregroundColors: foregroundColors == const $CopyWithPlaceholder() + ? _value.foregroundColors + // ignore: cast_nullable_to_non_nullable + : foregroundColors as MultiColor?, + backgroundColors: backgroundColors == const $CopyWithPlaceholder() + ? _value.backgroundColors + // ignore: cast_nullable_to_non_nullable + : backgroundColors as MultiColor?, + borderColors: borderColors == const $CopyWithPlaceholder() + ? _value.borderColors + // ignore: cast_nullable_to_non_nullable + : borderColors as MultiColor?, + stroke: stroke == const $CopyWithPlaceholder() + ? _value.stroke + // ignore: cast_nullable_to_non_nullable + : stroke as double?, + shadow: shadow == const $CopyWithPlaceholder() + ? _value.shadow + // ignore: cast_nullable_to_non_nullable + : shadow as BoxShadow?, + ); + } +} + +extension $FlatButtonStyleCopyWith on FlatButtonStyle { + /// Returns a callable class that can be used as follows: `instanceOfFlatButtonStyle.copyWith(...)` or like so:`instanceOfFlatButtonStyle.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$FlatButtonStyleCWProxy get copyWith => _$FlatButtonStyleCWProxyImpl(this); +} 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 e31acee7..2168895e 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 @@ -16,10 +16,13 @@ import 'dart:ui'; +import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; +part 'simple_icon_button_style.g.dart'; +@CopyWith() class SimpleIconButtonStyle extends ButtonStyle { const SimpleIconButtonStyle({ this.dimension, @@ -98,30 +101,4 @@ class SimpleIconButtonStyle extends ButtonStyle { @override SimpleIconButtonStyle mergeWith(SimpleIconButtonStyle? other) => SimpleIconButtonStyle.merge(this, other)!; - - @override - SimpleIconButtonStyle? lerpWith(SimpleIconButtonStyle? other, double t) => - SimpleIconButtonStyle.lerp(this, other, t); - - @override - SimpleIconButtonStyle copyWith({ - double? dimension, - BorderRadiusGeometry? radius, - EdgeInsetsGeometry? padding, - MultiColor? foregroundColors, - MultiColor? backgroundColors, - MultiColor? borderColors, - double? stroke, - BoxShadow? shadow, - }) => - SimpleIconButtonStyle( - dimension: dimension ?? this.dimension, - radius: radius ?? this.radius, - padding: padding ?? this.padding, - foregroundColors: foregroundColors ?? this.foregroundColors, - backgroundColors: backgroundColors ?? this.backgroundColors, - borderColors: borderColors ?? this.borderColors, - stroke: stroke ?? this.stroke, - shadow: shadow ?? this.shadow, - ); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.g.dart new file mode 100644 index 00000000..f0ee5153 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.g.dart @@ -0,0 +1,141 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'simple_icon_button_style.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$SimpleIconButtonStyleCWProxy { + SimpleIconButtonStyle dimension(double? dimension); + + SimpleIconButtonStyle radius(BorderRadiusGeometry? radius); + + SimpleIconButtonStyle padding(EdgeInsetsGeometry? padding); + + SimpleIconButtonStyle foregroundColors(MultiColor? foregroundColors); + + SimpleIconButtonStyle backgroundColors(MultiColor? backgroundColors); + + SimpleIconButtonStyle borderColors(MultiColor? borderColors); + + SimpleIconButtonStyle stroke(double? stroke); + + SimpleIconButtonStyle shadow(BoxShadow? shadow); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SimpleIconButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SimpleIconButtonStyle(...).copyWith(id: 12, name: "My name") + /// ```` + SimpleIconButtonStyle call({ + double? dimension, + BorderRadiusGeometry? radius, + EdgeInsetsGeometry? padding, + MultiColor? foregroundColors, + MultiColor? backgroundColors, + MultiColor? borderColors, + double? stroke, + BoxShadow? shadow, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSimpleIconButtonStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSimpleIconButtonStyle.copyWith.fieldName(...)` +class _$SimpleIconButtonStyleCWProxyImpl + implements _$SimpleIconButtonStyleCWProxy { + const _$SimpleIconButtonStyleCWProxyImpl(this._value); + + final SimpleIconButtonStyle _value; + + @override + SimpleIconButtonStyle dimension(double? dimension) => + this(dimension: dimension); + + @override + SimpleIconButtonStyle radius(BorderRadiusGeometry? radius) => + this(radius: radius); + + @override + SimpleIconButtonStyle padding(EdgeInsetsGeometry? padding) => + this(padding: padding); + + @override + SimpleIconButtonStyle foregroundColors(MultiColor? foregroundColors) => + this(foregroundColors: foregroundColors); + + @override + SimpleIconButtonStyle backgroundColors(MultiColor? backgroundColors) => + this(backgroundColors: backgroundColors); + + @override + SimpleIconButtonStyle borderColors(MultiColor? borderColors) => + this(borderColors: borderColors); + + @override + SimpleIconButtonStyle stroke(double? stroke) => this(stroke: stroke); + + @override + SimpleIconButtonStyle shadow(BoxShadow? shadow) => this(shadow: shadow); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SimpleIconButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SimpleIconButtonStyle(...).copyWith(id: 12, name: "My name") + /// ```` + SimpleIconButtonStyle call({ + Object? dimension = const $CopyWithPlaceholder(), + Object? radius = const $CopyWithPlaceholder(), + Object? padding = const $CopyWithPlaceholder(), + Object? foregroundColors = const $CopyWithPlaceholder(), + Object? backgroundColors = const $CopyWithPlaceholder(), + Object? borderColors = const $CopyWithPlaceholder(), + Object? stroke = const $CopyWithPlaceholder(), + Object? shadow = const $CopyWithPlaceholder(), + }) { + return SimpleIconButtonStyle( + dimension: dimension == const $CopyWithPlaceholder() + ? _value.dimension + // ignore: cast_nullable_to_non_nullable + : dimension as double?, + radius: radius == const $CopyWithPlaceholder() + ? _value.radius + // ignore: cast_nullable_to_non_nullable + : radius as BorderRadiusGeometry?, + padding: padding == const $CopyWithPlaceholder() + ? _value.padding + // ignore: cast_nullable_to_non_nullable + : padding as EdgeInsetsGeometry?, + foregroundColors: foregroundColors == const $CopyWithPlaceholder() + ? _value.foregroundColors + // ignore: cast_nullable_to_non_nullable + : foregroundColors as MultiColor?, + backgroundColors: backgroundColors == const $CopyWithPlaceholder() + ? _value.backgroundColors + // ignore: cast_nullable_to_non_nullable + : backgroundColors as MultiColor?, + borderColors: borderColors == const $CopyWithPlaceholder() + ? _value.borderColors + // ignore: cast_nullable_to_non_nullable + : borderColors as MultiColor?, + stroke: stroke == const $CopyWithPlaceholder() + ? _value.stroke + // ignore: cast_nullable_to_non_nullable + : stroke as double?, + shadow: shadow == const $CopyWithPlaceholder() + ? _value.shadow + // ignore: cast_nullable_to_non_nullable + : shadow as BoxShadow?, + ); + } +} + +extension $SimpleIconButtonStyleCopyWith on SimpleIconButtonStyle { + /// Returns a callable class that can be used as follows: `instanceOfSimpleIconButtonStyle.copyWith(...)` or like so:`instanceOfSimpleIconButtonStyle.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$SimpleIconButtonStyleCWProxy get copyWith => + _$SimpleIconButtonStyleCWProxyImpl(this); +} 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 a0815b3c..46bbcb35 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 @@ -16,10 +16,13 @@ import 'dart:ui'; +import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; +part 'symbol_button_style.g.dart'; +@CopyWith() class SymbolButtonStyle extends ButtonStyle { const SymbolButtonStyle({ this.label, @@ -106,32 +109,4 @@ class SymbolButtonStyle extends ButtonStyle { @override SymbolButtonStyle mergeWith(SymbolButtonStyle? other) => SymbolButtonStyle.merge(this, other)!; - - @override - SymbolButtonStyle? lerpWith(SymbolButtonStyle? other, double t) => - SymbolButtonStyle.lerp(this, other, t); - - @override - SymbolButtonStyle copyWith({ - TextStyle? label, - double? dimension, - BorderRadiusGeometry? radius, - EdgeInsetsGeometry? padding, - MultiColor? foregroundColors, - MultiColor? backgroundColors, - MultiColor? borderColors, - double? stroke, - BoxShadow? shadow, - }) => - SymbolButtonStyle( - label: label ?? this.label, - dimension: dimension ?? this.dimension, - radius: radius ?? this.radius, - padding: padding ?? this.padding, - foregroundColors: foregroundColors ?? this.foregroundColors, - backgroundColors: backgroundColors ?? this.backgroundColors, - borderColors: borderColors ?? this.borderColors, - stroke: stroke ?? this.stroke, - shadow: shadow ?? this.shadow, - ); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.g.dart new file mode 100644 index 00000000..a3233cec --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.g.dart @@ -0,0 +1,150 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'symbol_button_style.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$SymbolButtonStyleCWProxy { + SymbolButtonStyle label(TextStyle? label); + + SymbolButtonStyle dimension(double? dimension); + + SymbolButtonStyle radius(BorderRadiusGeometry? radius); + + SymbolButtonStyle padding(EdgeInsetsGeometry? padding); + + SymbolButtonStyle foregroundColors(MultiColor? foregroundColors); + + SymbolButtonStyle backgroundColors(MultiColor? backgroundColors); + + SymbolButtonStyle borderColors(MultiColor? borderColors); + + SymbolButtonStyle stroke(double? stroke); + + SymbolButtonStyle shadow(BoxShadow? shadow); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SymbolButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SymbolButtonStyle(...).copyWith(id: 12, name: "My name") + /// ```` + SymbolButtonStyle call({ + TextStyle? label, + double? dimension, + BorderRadiusGeometry? radius, + EdgeInsetsGeometry? padding, + MultiColor? foregroundColors, + MultiColor? backgroundColors, + MultiColor? borderColors, + double? stroke, + BoxShadow? shadow, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSymbolButtonStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSymbolButtonStyle.copyWith.fieldName(...)` +class _$SymbolButtonStyleCWProxyImpl implements _$SymbolButtonStyleCWProxy { + const _$SymbolButtonStyleCWProxyImpl(this._value); + + final SymbolButtonStyle _value; + + @override + SymbolButtonStyle label(TextStyle? label) => this(label: label); + + @override + SymbolButtonStyle dimension(double? dimension) => this(dimension: dimension); + + @override + SymbolButtonStyle radius(BorderRadiusGeometry? radius) => + this(radius: radius); + + @override + SymbolButtonStyle padding(EdgeInsetsGeometry? padding) => + this(padding: padding); + + @override + SymbolButtonStyle foregroundColors(MultiColor? foregroundColors) => + this(foregroundColors: foregroundColors); + + @override + SymbolButtonStyle backgroundColors(MultiColor? backgroundColors) => + this(backgroundColors: backgroundColors); + + @override + SymbolButtonStyle borderColors(MultiColor? borderColors) => + this(borderColors: borderColors); + + @override + SymbolButtonStyle stroke(double? stroke) => this(stroke: stroke); + + @override + SymbolButtonStyle shadow(BoxShadow? shadow) => this(shadow: shadow); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SymbolButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// SymbolButtonStyle(...).copyWith(id: 12, name: "My name") + /// ```` + SymbolButtonStyle call({ + Object? label = const $CopyWithPlaceholder(), + Object? dimension = const $CopyWithPlaceholder(), + Object? radius = const $CopyWithPlaceholder(), + Object? padding = const $CopyWithPlaceholder(), + Object? foregroundColors = const $CopyWithPlaceholder(), + Object? backgroundColors = const $CopyWithPlaceholder(), + Object? borderColors = const $CopyWithPlaceholder(), + Object? stroke = const $CopyWithPlaceholder(), + Object? shadow = const $CopyWithPlaceholder(), + }) { + return SymbolButtonStyle( + label: label == const $CopyWithPlaceholder() + ? _value.label + // ignore: cast_nullable_to_non_nullable + : label as TextStyle?, + dimension: dimension == const $CopyWithPlaceholder() + ? _value.dimension + // ignore: cast_nullable_to_non_nullable + : dimension as double?, + radius: radius == const $CopyWithPlaceholder() + ? _value.radius + // ignore: cast_nullable_to_non_nullable + : radius as BorderRadiusGeometry?, + padding: padding == const $CopyWithPlaceholder() + ? _value.padding + // ignore: cast_nullable_to_non_nullable + : padding as EdgeInsetsGeometry?, + foregroundColors: foregroundColors == const $CopyWithPlaceholder() + ? _value.foregroundColors + // ignore: cast_nullable_to_non_nullable + : foregroundColors as MultiColor?, + backgroundColors: backgroundColors == const $CopyWithPlaceholder() + ? _value.backgroundColors + // ignore: cast_nullable_to_non_nullable + : backgroundColors as MultiColor?, + borderColors: borderColors == const $CopyWithPlaceholder() + ? _value.borderColors + // ignore: cast_nullable_to_non_nullable + : borderColors as MultiColor?, + stroke: stroke == const $CopyWithPlaceholder() + ? _value.stroke + // ignore: cast_nullable_to_non_nullable + : stroke as double?, + shadow: shadow == const $CopyWithPlaceholder() + ? _value.shadow + // ignore: cast_nullable_to_non_nullable + : shadow as BoxShadow?, + ); + } +} + +extension $SymbolButtonStyleCopyWith on SymbolButtonStyle { + /// Returns a callable class that can be used as follows: `instanceOfSymbolButtonStyle.copyWith(...)` or like so:`instanceOfSymbolButtonStyle.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$SymbolButtonStyleCWProxy get copyWith => + _$SymbolButtonStyleCWProxyImpl(this); +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart index 43c3253c..3a8be8e2 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart @@ -16,8 +16,11 @@ import 'dart:ui'; +import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; +part 'loader_style.g.dart'; +@CopyWith() class LoaderStyle extends ThemeStyle { const LoaderStyle({ this.colors, @@ -67,20 +70,6 @@ class LoaderStyle extends ThemeStyle { @override LoaderStyle mergeWith(LoaderStyle? other) => LoaderStyle.merge(this, other)!; - @override - LoaderStyle? lerpWith(LoaderStyle? other, double t) => - LoaderStyle.lerp(this, other, t); - - @override - LoaderStyle copyWith({ - MultiColor? colors, - double? stroke, - }) => - LoaderStyle( - colors: colors ?? this.colors, - stroke: stroke ?? this.stroke, - ); - @override String toString() => 'LoaderStyle($colors, $stroke)'; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.g.dart new file mode 100644 index 00000000..86ec75c5 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.g.dart @@ -0,0 +1,67 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'loader_style.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$LoaderStyleCWProxy { + LoaderStyle colors(MultiColor? colors); + + LoaderStyle stroke(double? stroke); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `LoaderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// LoaderStyle(...).copyWith(id: 12, name: "My name") + /// ```` + LoaderStyle call({ + MultiColor? colors, + double? stroke, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfLoaderStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfLoaderStyle.copyWith.fieldName(...)` +class _$LoaderStyleCWProxyImpl implements _$LoaderStyleCWProxy { + const _$LoaderStyleCWProxyImpl(this._value); + + final LoaderStyle _value; + + @override + LoaderStyle colors(MultiColor? colors) => this(colors: colors); + + @override + LoaderStyle stroke(double? stroke) => this(stroke: stroke); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `LoaderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// LoaderStyle(...).copyWith(id: 12, name: "My name") + /// ```` + LoaderStyle call({ + Object? colors = const $CopyWithPlaceholder(), + Object? stroke = const $CopyWithPlaceholder(), + }) { + return LoaderStyle( + colors: colors == const $CopyWithPlaceholder() + ? _value.colors + // ignore: cast_nullable_to_non_nullable + : colors as MultiColor?, + stroke: stroke == const $CopyWithPlaceholder() + ? _value.stroke + // ignore: cast_nullable_to_non_nullable + : stroke as double?, + ); + } +} + +extension $LoaderStyleCopyWith on LoaderStyle { + /// Returns a callable class that can be used as follows: `instanceOfLoaderStyle.copyWith(...)` or like so:`instanceOfLoaderStyle.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$LoaderStyleCWProxy get copyWith => _$LoaderStyleCWProxyImpl(this); +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart index 43a03ff5..43ea1a9b 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; +part 'rich_text_builder_style.g.dart'; +@CopyWith() class RichTextBuilderStyle extends ThemeStyle { const RichTextBuilderStyle({ this.defaultStyle, @@ -66,18 +69,4 @@ class RichTextBuilderStyle extends ThemeStyle { @override RichTextBuilderStyle mergeWith(RichTextBuilderStyle? other) => RichTextBuilderStyle.merge(this, other)!; - - @override - RichTextBuilderStyle? lerpWith(RichTextBuilderStyle? other, double t) => - RichTextBuilderStyle.lerp(this, other, t); - - @override - RichTextBuilderStyle copyWith({ - TextStyle? defaultStyle, - Map? styles, - }) => - RichTextBuilderStyle( - defaultStyle: defaultStyle ?? this.defaultStyle, - styles: styles ?? this.styles, - ); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.g.dart new file mode 100644 index 00000000..8f74d5da --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.g.dart @@ -0,0 +1,71 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'rich_text_builder_style.dart'; + +// ************************************************************************** +// CopyWithGenerator +// ************************************************************************** + +abstract class _$RichTextBuilderStyleCWProxy { + RichTextBuilderStyle defaultStyle(TextStyle? defaultStyle); + + RichTextBuilderStyle styles(Map? styles); + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `RichTextBuilderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// RichTextBuilderStyle(...).copyWith(id: 12, name: "My name") + /// ```` + RichTextBuilderStyle call({ + TextStyle? defaultStyle, + Map? styles, + }); +} + +/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfRichTextBuilderStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfRichTextBuilderStyle.copyWith.fieldName(...)` +class _$RichTextBuilderStyleCWProxyImpl + implements _$RichTextBuilderStyleCWProxy { + const _$RichTextBuilderStyleCWProxyImpl(this._value); + + final RichTextBuilderStyle _value; + + @override + RichTextBuilderStyle defaultStyle(TextStyle? defaultStyle) => + this(defaultStyle: defaultStyle); + + @override + RichTextBuilderStyle styles(Map? styles) => + this(styles: styles); + + @override + + /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `RichTextBuilderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. + /// + /// Usage + /// ```dart + /// RichTextBuilderStyle(...).copyWith(id: 12, name: "My name") + /// ```` + RichTextBuilderStyle call({ + Object? defaultStyle = const $CopyWithPlaceholder(), + Object? styles = const $CopyWithPlaceholder(), + }) { + return RichTextBuilderStyle( + defaultStyle: defaultStyle == const $CopyWithPlaceholder() + ? _value.defaultStyle + // ignore: cast_nullable_to_non_nullable + : defaultStyle as TextStyle?, + styles: styles == const $CopyWithPlaceholder() + ? _value.styles + // ignore: cast_nullable_to_non_nullable + : styles as Map?, + ); + } +} + +extension $RichTextBuilderStyleCopyWith on RichTextBuilderStyle { + /// Returns a callable class that can be used as follows: `instanceOfRichTextBuilderStyle.copyWith(...)` or like so:`instanceOfRichTextBuilderStyle.copyWith.fieldName(...)`. + // ignore: library_private_types_in_public_api + _$RichTextBuilderStyleCWProxy get copyWith => + _$RichTextBuilderStyleCWProxyImpl(this); +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart index a456647e..1c19d260 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart @@ -20,7 +20,7 @@ import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; part 'text_input_style.g.dart'; @CopyWith() -class TextInputStyle { +class TextInputStyle extends ThemeStyle { TextInputStyle({ this.labelStyle, this.hintStyle, @@ -99,4 +99,8 @@ class TextInputStyle { iconColor: Color.lerp(a.iconColor, b.iconColor, t), ); } + + @override + TextInputStyle? mergeWith(TextInputStyle? other) => + TextInputStyle.merge(this, other); } 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 index 0f637eed..591b6fee 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/theme_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/theme_style.dart @@ -18,11 +18,5 @@ 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); - - /// Copy with (mandatory for mergeWith, needs to be simple and ignore `null`) - T copyWith(); + T? mergeWith(T? other); } 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 18a2cf0b..d707014c 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 @@ -67,7 +67,7 @@ class FileSelectionButtonScreen FileSelectionButtonStyle _resolve(BuildContext context, ButtonState state) { final FileSelectionButtonThemeResolver resolver = themeResolver ?? FileSelectionButtonThemeResolver( - customStyleFn: (context, extensionValue, {extra}) { + customStyleFn: (context, {extra}) { FileSelectionButtonStyle? style; switch (extra?.state) { case ControlState.disabled: diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart index 92399773..505e9e37 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart @@ -73,19 +73,17 @@ class FileSelectionButtonThemeResolver extends ThemeResolver< @override final FileSelectionButtonStyle? Function( - BuildContext context, - FileSelectionButtonStyle? extensionValue, { + BuildContext context, { ButtonState? extra, }) customStyleFn; @override FileSelectionButtonStyle? computeExtensionValueFn( BuildContext context, - FileSelectionButtonStyle defaultValue, FileSelectionButtonThemeExtension themeExtension, { ButtonState? extra, }) { - FileSelectionButtonStyle? style = defaultValue; + FileSelectionButtonStyle? style; switch (extra?.state) { case ControlState.disabled: style = themeExtension.disabledStyle; 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 88ff27f5..14b739fa 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 @@ -61,7 +61,7 @@ class FlatButtonScreen extends CubitScreen { FlatButtonStyle _resolve(BuildContext context, ControlState state) { final FlatButtonThemeResolver resolver = themeResolver ?? FlatButtonThemeResolver( - customStyleFn: (context, extensionValue, {extra}) { + customStyleFn: (context, {extra}) { switch (extra) { case ControlState.disabled: return disabledStyle; diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_theme_resolver.dart index cef92e2f..dfbe1349 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/flat_button/flat_button_theme_resolver.dart @@ -69,15 +69,13 @@ class FlatButtonThemeResolver extends ThemeResolver { SimpleIconButtonStyle _resolve(BuildContext context, ControlState state) { final SimpleIconButtonThemeResolver resolver = themeResolver ?? SimpleIconButtonThemeResolver( - customStyleFn: (context, extensionValue, {extra}) { + customStyleFn: (context, {extra}) { switch (extra) { case ControlState.disabled: return disabledStyle; 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 e2e427fd..6b586d82 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 @@ -63,7 +63,7 @@ class SymbolButtonScreen SymbolButtonStyle _resolve(BuildContext context, ButtonState state) { final SymbolButtonThemeResolver resolver = themeResolver ?? SymbolButtonThemeResolver( - customStyleFn: (context, extensionValue, {extra}) { + customStyleFn: (context, {extra}) { SymbolButtonStyle? style; switch (extra?.state) { case ControlState.disabled: diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart index bed01568..4628bd87 100644 --- a/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart @@ -69,19 +69,17 @@ class SymbolButtonThemeResolver extends ThemeResolver - LoaderStyle( - colors: themeExtension.colors, - stroke: themeExtension.stroke, - ), customStyleFn: (context, {extra}) => LoaderStyle( colors: colors, stroke: stroke, diff --git a/packages/wyatt_ui_kit/lib/src/components/loader/loader_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/loader/loader_theme_resolver.dart index 60047759..1b45ddaf 100644 --- a/packages/wyatt_ui_kit/lib/src/components/loader/loader_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/loader/loader_theme_resolver.dart @@ -21,7 +21,6 @@ import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; class LoaderThemeResolver extends ThemeResolver { const LoaderThemeResolver({ - required this.computeExtensionValueFn, required this.customStyleFn, }); @@ -42,12 +41,18 @@ class LoaderThemeResolver @override final LoaderStyle? Function( - BuildContext context, - LoaderStyle defaultValue, - LoaderThemeExtension themeExtension, { + BuildContext context, { void extra, - }) computeExtensionValueFn; + }) customStyleFn; @override - final LoaderStyle? Function(BuildContext context, {void extra}) customStyleFn; + LoaderStyle? computeExtensionValueFn( + BuildContext context, + LoaderThemeExtension themeExtension, { + void extra, + }) => + LoaderStyle( + colors: themeExtension.colors, + stroke: themeExtension.stroke, + ); } diff --git a/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder.dart b/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder.dart index 745d3462..0ca1798a 100644 --- a/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder.dart +++ b/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder.dart @@ -42,16 +42,6 @@ class RichTextBuilder extends RichTextBuilderComponent RichTextBuilderStyle _resolve(BuildContext context) { final RichTextBuilderThemeResolver resolver = themeResolver ?? RichTextBuilderThemeResolver( - computeExtensionValueFn: ( - context, - defaultValue, - themeExtension, { - extra, - }) => - RichTextBuilderStyle( - defaultStyle: themeExtension.defaultStyle, - styles: themeExtension.styles, - ), customStyleFn: (context, {extra}) => RichTextBuilderStyle( defaultStyle: defaultStyle, styles: styles, diff --git a/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder_theme_resolver.dart index f619d0a0..4661a264 100644 --- a/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder_theme_resolver.dart @@ -21,7 +21,6 @@ import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; class RichTextBuilderThemeResolver extends ThemeResolver { const RichTextBuilderThemeResolver({ - required this.computeExtensionValueFn, required this.customStyleFn, }); @@ -37,13 +36,18 @@ class RichTextBuilderThemeResolver extends ThemeResolver + RichTextBuilderStyle( + defaultStyle: themeExtension.defaultStyle, + styles: themeExtension.styles, + ); } diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart index 51a9d291..0766f8c0 100644 --- a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart @@ -195,7 +195,7 @@ class TextInputScreen extends CubitScreen { TextInputStyle _resolve(BuildContext context, TextInputState state) { final resolver = TextInputThemeResolver( - customStyleFn: (context, extensionValue, {extra}) { + customStyleFn: (context, {extra}) { TextInputStyle? textInputStyle; switch (extra?.controlState) { case ControlState.focused: @@ -230,10 +230,7 @@ class TextInputScreen extends CubitScreen { break; } - return TextInputStyle.merge( - extensionValue, - TextInputStyle.merge(textInputStyle, style), - ); + return TextInputStyle.merge(textInputStyle, style); }, ); diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart index b774c720..f421b762 100644 --- a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart @@ -28,8 +28,7 @@ class TextInputThemeResolver extends ThemeResolver Date: Tue, 21 Feb 2023 12:10:17 +0100 Subject: [PATCH 13/25] refactor(ui_components): add CopyWith method in ThemeStyle --- .../buttons/file_selection_button_style.dart | 28 +++++++++- .../entities/buttons/flat_button_style.dart | 26 ++++++++- .../buttons/simple_icon_button_style.dart | 26 ++++++++- .../entities/buttons/symbol_button_style.dart | 28 +++++++++- .../lib/src/domain/entities/loader_style.dart | 12 +++- .../rich_text_builder_style.dart | 14 ++++- .../text_inputs/text_input_style.dart | 56 ++++++++++++++----- .../lib/src/domain/entities/theme_style.dart | 3 + packages/wyatt_ui_components/pubspec.yaml | 2 + 9 files changed, 171 insertions(+), 24 deletions(-) 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 8585273e..1e61e3a5 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 @@ -107,6 +107,30 @@ class FileSelectionButtonStyle extends ButtonStyle { final TextStyle? subTitle; @override - FileSelectionButtonStyle mergeWith(FileSelectionButtonStyle? other) => - FileSelectionButtonStyle.merge(this, other)!; + FileSelectionButtonStyle? mergeWith(FileSelectionButtonStyle? other) => + FileSelectionButtonStyle.merge(this, other); + + @override + FileSelectionButtonStyle? copyWith({ + TextStyle? title, + TextStyle? subTitle, + BorderRadiusGeometry? radius, + EdgeInsetsGeometry? padding, + MultiColor? foregroundColors, + MultiColor? backgroundColors, + MultiColor? borderColors, + double? stroke, + BoxShadow? shadow, + }) => + FileSelectionButtonStyle( + title: title ?? this.title, + subTitle: subTitle ?? this.subTitle, + radius: radius ?? this.radius, + padding: padding ?? this.padding, + foregroundColors: foregroundColors ?? this.foregroundColors, + backgroundColors: backgroundColors ?? this.backgroundColors, + borderColors: borderColors ?? this.borderColors, + stroke: stroke ?? this.stroke, + shadow: shadow ?? this.shadow, + ); } 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 676d510c..50ac5fb2 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 @@ -99,6 +99,28 @@ class FlatButtonStyle extends ButtonStyle { final TextStyle? label; @override - FlatButtonStyle mergeWith(FlatButtonStyle? other) => - FlatButtonStyle.merge(this, other)!; + FlatButtonStyle? mergeWith(FlatButtonStyle? other) => + FlatButtonStyle.merge(this, other); + + @override + FlatButtonStyle? copyWith({ + TextStyle? label, + BorderRadiusGeometry? radius, + EdgeInsetsGeometry? padding, + MultiColor? foregroundColors, + MultiColor? backgroundColors, + MultiColor? borderColors, + double? stroke, + BoxShadow? shadow, + }) => + FlatButtonStyle( + label: label ?? this.label, + radius: radius ?? this.radius, + padding: padding ?? this.padding, + foregroundColors: foregroundColors ?? this.foregroundColors, + backgroundColors: backgroundColors ?? this.backgroundColors, + borderColors: borderColors ?? this.borderColors, + stroke: stroke ?? this.stroke, + shadow: shadow ?? this.shadow, + ); } 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 2168895e..298d32d2 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 @@ -99,6 +99,28 @@ class SimpleIconButtonStyle extends ButtonStyle { final double? dimension; @override - SimpleIconButtonStyle mergeWith(SimpleIconButtonStyle? other) => - SimpleIconButtonStyle.merge(this, other)!; + SimpleIconButtonStyle? mergeWith(SimpleIconButtonStyle? other) => + SimpleIconButtonStyle.merge(this, other); + + @override + SimpleIconButtonStyle copyWith({ + double? dimension, + BorderRadiusGeometry? radius, + EdgeInsetsGeometry? padding, + MultiColor? foregroundColors, + MultiColor? backgroundColors, + MultiColor? borderColors, + double? stroke, + BoxShadow? shadow, + }) => + SimpleIconButtonStyle( + dimension: dimension ?? this.dimension, + radius: radius ?? this.radius, + padding: padding ?? this.padding, + foregroundColors: foregroundColors ?? this.foregroundColors, + backgroundColors: backgroundColors ?? this.backgroundColors, + borderColors: borderColors ?? this.borderColors, + stroke: stroke ?? this.stroke, + shadow: shadow ?? this.shadow, + ); } 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 46bbcb35..9dcc9640 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 @@ -107,6 +107,30 @@ class SymbolButtonStyle extends ButtonStyle { final double? dimension; @override - SymbolButtonStyle mergeWith(SymbolButtonStyle? other) => - SymbolButtonStyle.merge(this, other)!; + SymbolButtonStyle? mergeWith(SymbolButtonStyle? other) => + SymbolButtonStyle.merge(this, other); + + @override + SymbolButtonStyle? copyWith({ + TextStyle? label, + double? dimension, + BorderRadiusGeometry? radius, + EdgeInsetsGeometry? padding, + MultiColor? foregroundColors, + MultiColor? backgroundColors, + MultiColor? borderColors, + double? stroke, + BoxShadow? shadow, + }) => + SymbolButtonStyle( + label: label ?? this.label, + dimension: dimension ?? this.dimension, + radius: radius ?? this.radius, + padding: padding ?? this.padding, + foregroundColors: foregroundColors ?? this.foregroundColors, + backgroundColors: backgroundColors ?? this.backgroundColors, + borderColors: borderColors ?? this.borderColors, + stroke: stroke ?? this.stroke, + shadow: shadow ?? this.shadow, + ); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart index 3a8be8e2..0f46cbba 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart @@ -68,7 +68,17 @@ class LoaderStyle extends ThemeStyle { final double? stroke; @override - LoaderStyle mergeWith(LoaderStyle? other) => LoaderStyle.merge(this, other)!; + LoaderStyle? mergeWith(LoaderStyle? other) => LoaderStyle.merge(this, other); + + @override + LoaderStyle copyWith({ + MultiColor? colors, + double? stroke, + }) => + LoaderStyle( + colors: colors ?? this.colors, + stroke: stroke ?? this.stroke, + ); @override String toString() => 'LoaderStyle($colors, $stroke)'; diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart index 43ea1a9b..48a21b3d 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart @@ -67,6 +67,16 @@ class RichTextBuilderStyle extends ThemeStyle { final Map? styles; @override - RichTextBuilderStyle mergeWith(RichTextBuilderStyle? other) => - RichTextBuilderStyle.merge(this, other)!; + RichTextBuilderStyle? mergeWith(RichTextBuilderStyle? other) => + RichTextBuilderStyle.merge(this, other); + + @override + RichTextBuilderStyle? copyWith({ + TextStyle? defaultStyle, + Map? styles, + }) => + RichTextBuilderStyle( + defaultStyle: defaultStyle ?? this.defaultStyle, + styles: styles ?? this.styles, + ); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart index 1c19d260..61640bcd 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart @@ -58,19 +58,19 @@ class TextInputStyle extends ThemeStyle { if (a == null) { return b.copyWith(); } - return a.copyWith( - labelStyle: b.labelStyle, - hintStyle: b.hintStyle, - backgroundColors: b.backgroundColors, - borderColors: b.borderColors, - boxShadow: b.boxShadow, - radius: b.radius, - inputStyle: b.inputStyle, - iconColor: b.iconColor, - prefixStyle: b.prefixStyle, - prefixIconColor: b.prefixIconColor, - suffixIconColor: b.suffixIconColor, - suffixStyle: b.suffixStyle, + return b.copyWith( + labelStyle: a.labelStyle, + hintStyle: a.hintStyle, + backgroundColors: a.backgroundColors, + borderColors: a.borderColors, + boxShadow: a.boxShadow, + radius: a.radius, + inputStyle: a.inputStyle, + iconColor: a.iconColor, + prefixStyle: a.prefixStyle, + prefixIconColor: a.prefixIconColor, + suffixIconColor: a.suffixIconColor, + suffixStyle: a.suffixStyle, ); } @@ -103,4 +103,34 @@ class TextInputStyle extends ThemeStyle { @override TextInputStyle? mergeWith(TextInputStyle? other) => TextInputStyle.merge(this, other); + + @override + TextInputStyle copyWith({ + TextStyle? labelStyle, + TextStyle? hintStyle, + MultiColor? backgroundColors, + MultiColor? borderColors, + BoxShadow? boxShadow, + BorderRadiusGeometry? radius, + TextStyle? inputStyle, + Color? iconColor, + TextStyle? prefixStyle, + Color? prefixIconColor, + TextStyle? suffixStyle, + Color? suffixIconColor, + }) => + TextInputStyle( + labelStyle: labelStyle ?? this.labelStyle, + hintStyle: hintStyle ?? this.hintStyle, + backgroundColors: backgroundColors ?? this.backgroundColors, + radius: radius ?? this.radius, + borderColors: borderColors ?? this.borderColors, + boxShadow: boxShadow ?? this.boxShadow, + inputStyle: inputStyle ?? this.inputStyle, + prefixStyle: prefixStyle ?? this.prefixStyle, + suffixStyle: suffixStyle ?? this.suffixStyle, + prefixIconColor: prefixIconColor ?? this.prefixIconColor, + suffixIconColor: suffixIconColor ?? this.suffixIconColor, + iconColor: iconColor ?? this.iconColor, + ); } 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 index 591b6fee..a0a69ffb 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/theme_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/theme_style.dart @@ -19,4 +19,7 @@ abstract class ThemeStyle { /// Merges non-null `other` attributes in `this` and returns a copy. T? mergeWith(T? other); + + /// Copy with (mandatory for mergeWith, needs to be simple and ignore `null`) + T? copyWith(); } diff --git a/packages/wyatt_ui_components/pubspec.yaml b/packages/wyatt_ui_components/pubspec.yaml index 395554ea..865b67f9 100644 --- a/packages/wyatt_ui_components/pubspec.yaml +++ b/packages/wyatt_ui_components/pubspec.yaml @@ -15,11 +15,13 @@ dependencies: git: url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git path: packages/wyatt_component_copy_with_extension + freezed_annotation: ^2.2.0 dev_dependencies: build_runner: ^2.3.3 copy_with_extension_gen: ^5.0.0 flutter_test: { sdk: flutter } + freezed: ^2.3.2 wyatt_analysis: hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub version: ^2.4.0 -- 2.47.2 From eda643e9b4667b5e602b2841ea243b56770daa53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 13:09:20 +0100 Subject: [PATCH 14/25] chore(ui_components): remove g files and copy with deps --- .../buttons/file_selection_button_style.dart | 3 - .../file_selection_button_style.g.dart | 152 -------------- .../entities/buttons/flat_button_style.dart | 3 - .../entities/buttons/flat_button_style.g.dart | 137 ------------- .../buttons/simple_icon_button_style.dart | 3 - .../buttons/simple_icon_button_style.g.dart | 141 ------------- .../entities/buttons/symbol_button_style.dart | 3 - .../buttons/symbol_button_style.g.dart | 150 -------------- .../lib/src/domain/entities/loader_style.dart | 3 - .../src/domain/entities/loader_style.g.dart | 67 ------- .../rich_text_builder_style.dart | 3 - .../rich_text_builder_style.g.dart | 71 ------- .../text_inputs/text_input_style.dart | 3 - .../text_inputs/text_input_style.g.dart | 185 ------------------ packages/wyatt_ui_components/pubspec.yaml | 2 - 15 files changed, 926 deletions(-) delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.g.dart delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.g.dart delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.g.dart delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.g.dart delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/loader_style.g.dart delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.g.dart delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.g.dart 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 1e61e3a5..85f20b88 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 @@ -16,13 +16,10 @@ import 'dart:ui'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; -part 'file_selection_button_style.g.dart'; -@CopyWith() class FileSelectionButtonStyle extends ButtonStyle { const FileSelectionButtonStyle({ this.title, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.g.dart deleted file mode 100644 index 6576a261..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/file_selection_button_style.g.dart +++ /dev/null @@ -1,152 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'file_selection_button_style.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$FileSelectionButtonStyleCWProxy { - FileSelectionButtonStyle title(TextStyle? title); - - FileSelectionButtonStyle subTitle(TextStyle? subTitle); - - FileSelectionButtonStyle radius(BorderRadiusGeometry? radius); - - FileSelectionButtonStyle padding(EdgeInsetsGeometry? padding); - - FileSelectionButtonStyle foregroundColors(MultiColor? foregroundColors); - - FileSelectionButtonStyle backgroundColors(MultiColor? backgroundColors); - - FileSelectionButtonStyle borderColors(MultiColor? borderColors); - - FileSelectionButtonStyle stroke(double? stroke); - - FileSelectionButtonStyle shadow(BoxShadow? shadow); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FileSelectionButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// FileSelectionButtonStyle(...).copyWith(id: 12, name: "My name") - /// ```` - FileSelectionButtonStyle call({ - TextStyle? title, - TextStyle? subTitle, - BorderRadiusGeometry? radius, - EdgeInsetsGeometry? padding, - MultiColor? foregroundColors, - MultiColor? backgroundColors, - MultiColor? borderColors, - double? stroke, - BoxShadow? shadow, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfFileSelectionButtonStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfFileSelectionButtonStyle.copyWith.fieldName(...)` -class _$FileSelectionButtonStyleCWProxyImpl - implements _$FileSelectionButtonStyleCWProxy { - const _$FileSelectionButtonStyleCWProxyImpl(this._value); - - final FileSelectionButtonStyle _value; - - @override - FileSelectionButtonStyle title(TextStyle? title) => this(title: title); - - @override - FileSelectionButtonStyle subTitle(TextStyle? subTitle) => - this(subTitle: subTitle); - - @override - FileSelectionButtonStyle radius(BorderRadiusGeometry? radius) => - this(radius: radius); - - @override - FileSelectionButtonStyle padding(EdgeInsetsGeometry? padding) => - this(padding: padding); - - @override - FileSelectionButtonStyle foregroundColors(MultiColor? foregroundColors) => - this(foregroundColors: foregroundColors); - - @override - FileSelectionButtonStyle backgroundColors(MultiColor? backgroundColors) => - this(backgroundColors: backgroundColors); - - @override - FileSelectionButtonStyle borderColors(MultiColor? borderColors) => - this(borderColors: borderColors); - - @override - FileSelectionButtonStyle stroke(double? stroke) => this(stroke: stroke); - - @override - FileSelectionButtonStyle shadow(BoxShadow? shadow) => this(shadow: shadow); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FileSelectionButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// FileSelectionButtonStyle(...).copyWith(id: 12, name: "My name") - /// ```` - FileSelectionButtonStyle call({ - Object? title = const $CopyWithPlaceholder(), - Object? subTitle = const $CopyWithPlaceholder(), - Object? radius = const $CopyWithPlaceholder(), - Object? padding = const $CopyWithPlaceholder(), - Object? foregroundColors = const $CopyWithPlaceholder(), - Object? backgroundColors = const $CopyWithPlaceholder(), - Object? borderColors = const $CopyWithPlaceholder(), - Object? stroke = const $CopyWithPlaceholder(), - Object? shadow = const $CopyWithPlaceholder(), - }) { - return FileSelectionButtonStyle( - title: title == const $CopyWithPlaceholder() - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as TextStyle?, - subTitle: subTitle == const $CopyWithPlaceholder() - ? _value.subTitle - // ignore: cast_nullable_to_non_nullable - : subTitle as TextStyle?, - radius: radius == const $CopyWithPlaceholder() - ? _value.radius - // ignore: cast_nullable_to_non_nullable - : radius as BorderRadiusGeometry?, - padding: padding == const $CopyWithPlaceholder() - ? _value.padding - // ignore: cast_nullable_to_non_nullable - : padding as EdgeInsetsGeometry?, - foregroundColors: foregroundColors == const $CopyWithPlaceholder() - ? _value.foregroundColors - // ignore: cast_nullable_to_non_nullable - : foregroundColors as MultiColor?, - backgroundColors: backgroundColors == const $CopyWithPlaceholder() - ? _value.backgroundColors - // ignore: cast_nullable_to_non_nullable - : backgroundColors as MultiColor?, - borderColors: borderColors == const $CopyWithPlaceholder() - ? _value.borderColors - // ignore: cast_nullable_to_non_nullable - : borderColors as MultiColor?, - stroke: stroke == const $CopyWithPlaceholder() - ? _value.stroke - // ignore: cast_nullable_to_non_nullable - : stroke as double?, - shadow: shadow == const $CopyWithPlaceholder() - ? _value.shadow - // ignore: cast_nullable_to_non_nullable - : shadow as BoxShadow?, - ); - } -} - -extension $FileSelectionButtonStyleCopyWith on FileSelectionButtonStyle { - /// Returns a callable class that can be used as follows: `instanceOfFileSelectionButtonStyle.copyWith(...)` or like so:`instanceOfFileSelectionButtonStyle.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$FileSelectionButtonStyleCWProxy get copyWith => - _$FileSelectionButtonStyleCWProxyImpl(this); -} 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 50ac5fb2..4a15cc42 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 @@ -16,13 +16,10 @@ import 'dart:ui'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; -part 'flat_button_style.g.dart'; -@CopyWith() class FlatButtonStyle extends ButtonStyle { const FlatButtonStyle({ this.label, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.g.dart deleted file mode 100644 index 939a48e1..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.g.dart +++ /dev/null @@ -1,137 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'flat_button_style.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$FlatButtonStyleCWProxy { - FlatButtonStyle label(TextStyle? label); - - FlatButtonStyle radius(BorderRadiusGeometry? radius); - - FlatButtonStyle padding(EdgeInsetsGeometry? padding); - - FlatButtonStyle foregroundColors(MultiColor? foregroundColors); - - FlatButtonStyle backgroundColors(MultiColor? backgroundColors); - - FlatButtonStyle borderColors(MultiColor? borderColors); - - FlatButtonStyle stroke(double? stroke); - - FlatButtonStyle shadow(BoxShadow? shadow); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FlatButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// FlatButtonStyle(...).copyWith(id: 12, name: "My name") - /// ```` - FlatButtonStyle call({ - TextStyle? label, - BorderRadiusGeometry? radius, - EdgeInsetsGeometry? padding, - MultiColor? foregroundColors, - MultiColor? backgroundColors, - MultiColor? borderColors, - double? stroke, - BoxShadow? shadow, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfFlatButtonStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfFlatButtonStyle.copyWith.fieldName(...)` -class _$FlatButtonStyleCWProxyImpl implements _$FlatButtonStyleCWProxy { - const _$FlatButtonStyleCWProxyImpl(this._value); - - final FlatButtonStyle _value; - - @override - FlatButtonStyle label(TextStyle? label) => this(label: label); - - @override - FlatButtonStyle radius(BorderRadiusGeometry? radius) => this(radius: radius); - - @override - FlatButtonStyle padding(EdgeInsetsGeometry? padding) => - this(padding: padding); - - @override - FlatButtonStyle foregroundColors(MultiColor? foregroundColors) => - this(foregroundColors: foregroundColors); - - @override - FlatButtonStyle backgroundColors(MultiColor? backgroundColors) => - this(backgroundColors: backgroundColors); - - @override - FlatButtonStyle borderColors(MultiColor? borderColors) => - this(borderColors: borderColors); - - @override - FlatButtonStyle stroke(double? stroke) => this(stroke: stroke); - - @override - FlatButtonStyle shadow(BoxShadow? shadow) => this(shadow: shadow); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FlatButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// FlatButtonStyle(...).copyWith(id: 12, name: "My name") - /// ```` - FlatButtonStyle call({ - Object? label = const $CopyWithPlaceholder(), - Object? radius = const $CopyWithPlaceholder(), - Object? padding = const $CopyWithPlaceholder(), - Object? foregroundColors = const $CopyWithPlaceholder(), - Object? backgroundColors = const $CopyWithPlaceholder(), - Object? borderColors = const $CopyWithPlaceholder(), - Object? stroke = const $CopyWithPlaceholder(), - Object? shadow = const $CopyWithPlaceholder(), - }) { - return FlatButtonStyle( - label: label == const $CopyWithPlaceholder() - ? _value.label - // ignore: cast_nullable_to_non_nullable - : label as TextStyle?, - radius: radius == const $CopyWithPlaceholder() - ? _value.radius - // ignore: cast_nullable_to_non_nullable - : radius as BorderRadiusGeometry?, - padding: padding == const $CopyWithPlaceholder() - ? _value.padding - // ignore: cast_nullable_to_non_nullable - : padding as EdgeInsetsGeometry?, - foregroundColors: foregroundColors == const $CopyWithPlaceholder() - ? _value.foregroundColors - // ignore: cast_nullable_to_non_nullable - : foregroundColors as MultiColor?, - backgroundColors: backgroundColors == const $CopyWithPlaceholder() - ? _value.backgroundColors - // ignore: cast_nullable_to_non_nullable - : backgroundColors as MultiColor?, - borderColors: borderColors == const $CopyWithPlaceholder() - ? _value.borderColors - // ignore: cast_nullable_to_non_nullable - : borderColors as MultiColor?, - stroke: stroke == const $CopyWithPlaceholder() - ? _value.stroke - // ignore: cast_nullable_to_non_nullable - : stroke as double?, - shadow: shadow == const $CopyWithPlaceholder() - ? _value.shadow - // ignore: cast_nullable_to_non_nullable - : shadow as BoxShadow?, - ); - } -} - -extension $FlatButtonStyleCopyWith on FlatButtonStyle { - /// Returns a callable class that can be used as follows: `instanceOfFlatButtonStyle.copyWith(...)` or like so:`instanceOfFlatButtonStyle.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$FlatButtonStyleCWProxy get copyWith => _$FlatButtonStyleCWProxyImpl(this); -} 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 298d32d2..f2ea057b 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 @@ -16,13 +16,10 @@ import 'dart:ui'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; -part 'simple_icon_button_style.g.dart'; -@CopyWith() class SimpleIconButtonStyle extends ButtonStyle { const SimpleIconButtonStyle({ this.dimension, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.g.dart deleted file mode 100644 index f0ee5153..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/simple_icon_button_style.g.dart +++ /dev/null @@ -1,141 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'simple_icon_button_style.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$SimpleIconButtonStyleCWProxy { - SimpleIconButtonStyle dimension(double? dimension); - - SimpleIconButtonStyle radius(BorderRadiusGeometry? radius); - - SimpleIconButtonStyle padding(EdgeInsetsGeometry? padding); - - SimpleIconButtonStyle foregroundColors(MultiColor? foregroundColors); - - SimpleIconButtonStyle backgroundColors(MultiColor? backgroundColors); - - SimpleIconButtonStyle borderColors(MultiColor? borderColors); - - SimpleIconButtonStyle stroke(double? stroke); - - SimpleIconButtonStyle shadow(BoxShadow? shadow); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SimpleIconButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// SimpleIconButtonStyle(...).copyWith(id: 12, name: "My name") - /// ```` - SimpleIconButtonStyle call({ - double? dimension, - BorderRadiusGeometry? radius, - EdgeInsetsGeometry? padding, - MultiColor? foregroundColors, - MultiColor? backgroundColors, - MultiColor? borderColors, - double? stroke, - BoxShadow? shadow, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSimpleIconButtonStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSimpleIconButtonStyle.copyWith.fieldName(...)` -class _$SimpleIconButtonStyleCWProxyImpl - implements _$SimpleIconButtonStyleCWProxy { - const _$SimpleIconButtonStyleCWProxyImpl(this._value); - - final SimpleIconButtonStyle _value; - - @override - SimpleIconButtonStyle dimension(double? dimension) => - this(dimension: dimension); - - @override - SimpleIconButtonStyle radius(BorderRadiusGeometry? radius) => - this(radius: radius); - - @override - SimpleIconButtonStyle padding(EdgeInsetsGeometry? padding) => - this(padding: padding); - - @override - SimpleIconButtonStyle foregroundColors(MultiColor? foregroundColors) => - this(foregroundColors: foregroundColors); - - @override - SimpleIconButtonStyle backgroundColors(MultiColor? backgroundColors) => - this(backgroundColors: backgroundColors); - - @override - SimpleIconButtonStyle borderColors(MultiColor? borderColors) => - this(borderColors: borderColors); - - @override - SimpleIconButtonStyle stroke(double? stroke) => this(stroke: stroke); - - @override - SimpleIconButtonStyle shadow(BoxShadow? shadow) => this(shadow: shadow); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SimpleIconButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// SimpleIconButtonStyle(...).copyWith(id: 12, name: "My name") - /// ```` - SimpleIconButtonStyle call({ - Object? dimension = const $CopyWithPlaceholder(), - Object? radius = const $CopyWithPlaceholder(), - Object? padding = const $CopyWithPlaceholder(), - Object? foregroundColors = const $CopyWithPlaceholder(), - Object? backgroundColors = const $CopyWithPlaceholder(), - Object? borderColors = const $CopyWithPlaceholder(), - Object? stroke = const $CopyWithPlaceholder(), - Object? shadow = const $CopyWithPlaceholder(), - }) { - return SimpleIconButtonStyle( - dimension: dimension == const $CopyWithPlaceholder() - ? _value.dimension - // ignore: cast_nullable_to_non_nullable - : dimension as double?, - radius: radius == const $CopyWithPlaceholder() - ? _value.radius - // ignore: cast_nullable_to_non_nullable - : radius as BorderRadiusGeometry?, - padding: padding == const $CopyWithPlaceholder() - ? _value.padding - // ignore: cast_nullable_to_non_nullable - : padding as EdgeInsetsGeometry?, - foregroundColors: foregroundColors == const $CopyWithPlaceholder() - ? _value.foregroundColors - // ignore: cast_nullable_to_non_nullable - : foregroundColors as MultiColor?, - backgroundColors: backgroundColors == const $CopyWithPlaceholder() - ? _value.backgroundColors - // ignore: cast_nullable_to_non_nullable - : backgroundColors as MultiColor?, - borderColors: borderColors == const $CopyWithPlaceholder() - ? _value.borderColors - // ignore: cast_nullable_to_non_nullable - : borderColors as MultiColor?, - stroke: stroke == const $CopyWithPlaceholder() - ? _value.stroke - // ignore: cast_nullable_to_non_nullable - : stroke as double?, - shadow: shadow == const $CopyWithPlaceholder() - ? _value.shadow - // ignore: cast_nullable_to_non_nullable - : shadow as BoxShadow?, - ); - } -} - -extension $SimpleIconButtonStyleCopyWith on SimpleIconButtonStyle { - /// Returns a callable class that can be used as follows: `instanceOfSimpleIconButtonStyle.copyWith(...)` or like so:`instanceOfSimpleIconButtonStyle.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$SimpleIconButtonStyleCWProxy get copyWith => - _$SimpleIconButtonStyleCWProxyImpl(this); -} 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 9dcc9640..1357724e 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 @@ -16,13 +16,10 @@ import 'dart:ui'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; -part 'symbol_button_style.g.dart'; -@CopyWith() class SymbolButtonStyle extends ButtonStyle { const SymbolButtonStyle({ this.label, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.g.dart deleted file mode 100644 index a3233cec..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.g.dart +++ /dev/null @@ -1,150 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'symbol_button_style.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$SymbolButtonStyleCWProxy { - SymbolButtonStyle label(TextStyle? label); - - SymbolButtonStyle dimension(double? dimension); - - SymbolButtonStyle radius(BorderRadiusGeometry? radius); - - SymbolButtonStyle padding(EdgeInsetsGeometry? padding); - - SymbolButtonStyle foregroundColors(MultiColor? foregroundColors); - - SymbolButtonStyle backgroundColors(MultiColor? backgroundColors); - - SymbolButtonStyle borderColors(MultiColor? borderColors); - - SymbolButtonStyle stroke(double? stroke); - - SymbolButtonStyle shadow(BoxShadow? shadow); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SymbolButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// SymbolButtonStyle(...).copyWith(id: 12, name: "My name") - /// ```` - SymbolButtonStyle call({ - TextStyle? label, - double? dimension, - BorderRadiusGeometry? radius, - EdgeInsetsGeometry? padding, - MultiColor? foregroundColors, - MultiColor? backgroundColors, - MultiColor? borderColors, - double? stroke, - BoxShadow? shadow, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSymbolButtonStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSymbolButtonStyle.copyWith.fieldName(...)` -class _$SymbolButtonStyleCWProxyImpl implements _$SymbolButtonStyleCWProxy { - const _$SymbolButtonStyleCWProxyImpl(this._value); - - final SymbolButtonStyle _value; - - @override - SymbolButtonStyle label(TextStyle? label) => this(label: label); - - @override - SymbolButtonStyle dimension(double? dimension) => this(dimension: dimension); - - @override - SymbolButtonStyle radius(BorderRadiusGeometry? radius) => - this(radius: radius); - - @override - SymbolButtonStyle padding(EdgeInsetsGeometry? padding) => - this(padding: padding); - - @override - SymbolButtonStyle foregroundColors(MultiColor? foregroundColors) => - this(foregroundColors: foregroundColors); - - @override - SymbolButtonStyle backgroundColors(MultiColor? backgroundColors) => - this(backgroundColors: backgroundColors); - - @override - SymbolButtonStyle borderColors(MultiColor? borderColors) => - this(borderColors: borderColors); - - @override - SymbolButtonStyle stroke(double? stroke) => this(stroke: stroke); - - @override - SymbolButtonStyle shadow(BoxShadow? shadow) => this(shadow: shadow); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SymbolButtonStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// SymbolButtonStyle(...).copyWith(id: 12, name: "My name") - /// ```` - SymbolButtonStyle call({ - Object? label = const $CopyWithPlaceholder(), - Object? dimension = const $CopyWithPlaceholder(), - Object? radius = const $CopyWithPlaceholder(), - Object? padding = const $CopyWithPlaceholder(), - Object? foregroundColors = const $CopyWithPlaceholder(), - Object? backgroundColors = const $CopyWithPlaceholder(), - Object? borderColors = const $CopyWithPlaceholder(), - Object? stroke = const $CopyWithPlaceholder(), - Object? shadow = const $CopyWithPlaceholder(), - }) { - return SymbolButtonStyle( - label: label == const $CopyWithPlaceholder() - ? _value.label - // ignore: cast_nullable_to_non_nullable - : label as TextStyle?, - dimension: dimension == const $CopyWithPlaceholder() - ? _value.dimension - // ignore: cast_nullable_to_non_nullable - : dimension as double?, - radius: radius == const $CopyWithPlaceholder() - ? _value.radius - // ignore: cast_nullable_to_non_nullable - : radius as BorderRadiusGeometry?, - padding: padding == const $CopyWithPlaceholder() - ? _value.padding - // ignore: cast_nullable_to_non_nullable - : padding as EdgeInsetsGeometry?, - foregroundColors: foregroundColors == const $CopyWithPlaceholder() - ? _value.foregroundColors - // ignore: cast_nullable_to_non_nullable - : foregroundColors as MultiColor?, - backgroundColors: backgroundColors == const $CopyWithPlaceholder() - ? _value.backgroundColors - // ignore: cast_nullable_to_non_nullable - : backgroundColors as MultiColor?, - borderColors: borderColors == const $CopyWithPlaceholder() - ? _value.borderColors - // ignore: cast_nullable_to_non_nullable - : borderColors as MultiColor?, - stroke: stroke == const $CopyWithPlaceholder() - ? _value.stroke - // ignore: cast_nullable_to_non_nullable - : stroke as double?, - shadow: shadow == const $CopyWithPlaceholder() - ? _value.shadow - // ignore: cast_nullable_to_non_nullable - : shadow as BoxShadow?, - ); - } -} - -extension $SymbolButtonStyleCopyWith on SymbolButtonStyle { - /// Returns a callable class that can be used as follows: `instanceOfSymbolButtonStyle.copyWith(...)` or like so:`instanceOfSymbolButtonStyle.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$SymbolButtonStyleCWProxy get copyWith => - _$SymbolButtonStyleCWProxyImpl(this); -} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart index 0f46cbba..b32c3a35 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart @@ -16,11 +16,8 @@ import 'dart:ui'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; -part 'loader_style.g.dart'; -@CopyWith() class LoaderStyle extends ThemeStyle { const LoaderStyle({ this.colors, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.g.dart deleted file mode 100644 index 86ec75c5..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.g.dart +++ /dev/null @@ -1,67 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'loader_style.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$LoaderStyleCWProxy { - LoaderStyle colors(MultiColor? colors); - - LoaderStyle stroke(double? stroke); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `LoaderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// LoaderStyle(...).copyWith(id: 12, name: "My name") - /// ```` - LoaderStyle call({ - MultiColor? colors, - double? stroke, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfLoaderStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfLoaderStyle.copyWith.fieldName(...)` -class _$LoaderStyleCWProxyImpl implements _$LoaderStyleCWProxy { - const _$LoaderStyleCWProxyImpl(this._value); - - final LoaderStyle _value; - - @override - LoaderStyle colors(MultiColor? colors) => this(colors: colors); - - @override - LoaderStyle stroke(double? stroke) => this(stroke: stroke); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `LoaderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// LoaderStyle(...).copyWith(id: 12, name: "My name") - /// ```` - LoaderStyle call({ - Object? colors = const $CopyWithPlaceholder(), - Object? stroke = const $CopyWithPlaceholder(), - }) { - return LoaderStyle( - colors: colors == const $CopyWithPlaceholder() - ? _value.colors - // ignore: cast_nullable_to_non_nullable - : colors as MultiColor?, - stroke: stroke == const $CopyWithPlaceholder() - ? _value.stroke - // ignore: cast_nullable_to_non_nullable - : stroke as double?, - ); - } -} - -extension $LoaderStyleCopyWith on LoaderStyle { - /// Returns a callable class that can be used as follows: `instanceOfLoaderStyle.copyWith(...)` or like so:`instanceOfLoaderStyle.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$LoaderStyleCWProxy get copyWith => _$LoaderStyleCWProxyImpl(this); -} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart index 48a21b3d..814bc237 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.dart @@ -14,12 +14,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/widgets.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; -part 'rich_text_builder_style.g.dart'; -@CopyWith() class RichTextBuilderStyle extends ThemeStyle { const RichTextBuilderStyle({ this.defaultStyle, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.g.dart deleted file mode 100644 index 8f74d5da..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/rich_text_builder_style.g.dart +++ /dev/null @@ -1,71 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'rich_text_builder_style.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$RichTextBuilderStyleCWProxy { - RichTextBuilderStyle defaultStyle(TextStyle? defaultStyle); - - RichTextBuilderStyle styles(Map? styles); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `RichTextBuilderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// RichTextBuilderStyle(...).copyWith(id: 12, name: "My name") - /// ```` - RichTextBuilderStyle call({ - TextStyle? defaultStyle, - Map? styles, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfRichTextBuilderStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfRichTextBuilderStyle.copyWith.fieldName(...)` -class _$RichTextBuilderStyleCWProxyImpl - implements _$RichTextBuilderStyleCWProxy { - const _$RichTextBuilderStyleCWProxyImpl(this._value); - - final RichTextBuilderStyle _value; - - @override - RichTextBuilderStyle defaultStyle(TextStyle? defaultStyle) => - this(defaultStyle: defaultStyle); - - @override - RichTextBuilderStyle styles(Map? styles) => - this(styles: styles); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `RichTextBuilderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// RichTextBuilderStyle(...).copyWith(id: 12, name: "My name") - /// ```` - RichTextBuilderStyle call({ - Object? defaultStyle = const $CopyWithPlaceholder(), - Object? styles = const $CopyWithPlaceholder(), - }) { - return RichTextBuilderStyle( - defaultStyle: defaultStyle == const $CopyWithPlaceholder() - ? _value.defaultStyle - // ignore: cast_nullable_to_non_nullable - : defaultStyle as TextStyle?, - styles: styles == const $CopyWithPlaceholder() - ? _value.styles - // ignore: cast_nullable_to_non_nullable - : styles as Map?, - ); - } -} - -extension $RichTextBuilderStyleCopyWith on RichTextBuilderStyle { - /// Returns a callable class that can be used as follows: `instanceOfRichTextBuilderStyle.copyWith(...)` or like so:`instanceOfRichTextBuilderStyle.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$RichTextBuilderStyleCWProxy get copyWith => - _$RichTextBuilderStyleCWProxyImpl(this); -} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart index 61640bcd..72855a4e 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart @@ -14,12 +14,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/material.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; -part 'text_input_style.g.dart'; -@CopyWith() class TextInputStyle extends ThemeStyle { TextInputStyle({ this.labelStyle, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.g.dart deleted file mode 100644 index 972c2b88..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.g.dart +++ /dev/null @@ -1,185 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'text_input_style.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$TextInputStyleCWProxy { - TextInputStyle labelStyle(TextStyle? labelStyle); - - TextInputStyle hintStyle(TextStyle? hintStyle); - - TextInputStyle backgroundColors(MultiColor? backgroundColors); - - TextInputStyle borderColors(MultiColor? borderColors); - - TextInputStyle boxShadow(BoxShadow? boxShadow); - - TextInputStyle radius(BorderRadiusGeometry? radius); - - TextInputStyle inputStyle(TextStyle? inputStyle); - - TextInputStyle iconColor(Color? iconColor); - - TextInputStyle prefixStyle(TextStyle? prefixStyle); - - TextInputStyle prefixIconColor(Color? prefixIconColor); - - TextInputStyle suffixStyle(TextStyle? suffixStyle); - - TextInputStyle suffixIconColor(Color? suffixIconColor); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TextInputStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// TextInputStyle(...).copyWith(id: 12, name: "My name") - /// ```` - TextInputStyle call({ - TextStyle? labelStyle, - TextStyle? hintStyle, - MultiColor? backgroundColors, - MultiColor? borderColors, - BoxShadow? boxShadow, - BorderRadiusGeometry? radius, - TextStyle? inputStyle, - Color? iconColor, - TextStyle? prefixStyle, - Color? prefixIconColor, - TextStyle? suffixStyle, - Color? suffixIconColor, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTextInputStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTextInputStyle.copyWith.fieldName(...)` -class _$TextInputStyleCWProxyImpl implements _$TextInputStyleCWProxy { - const _$TextInputStyleCWProxyImpl(this._value); - - final TextInputStyle _value; - - @override - TextInputStyle labelStyle(TextStyle? labelStyle) => - this(labelStyle: labelStyle); - - @override - TextInputStyle hintStyle(TextStyle? hintStyle) => this(hintStyle: hintStyle); - - @override - TextInputStyle backgroundColors(MultiColor? backgroundColors) => - this(backgroundColors: backgroundColors); - - @override - TextInputStyle borderColors(MultiColor? borderColors) => - this(borderColors: borderColors); - - @override - TextInputStyle boxShadow(BoxShadow? boxShadow) => this(boxShadow: boxShadow); - - @override - TextInputStyle radius(BorderRadiusGeometry? radius) => this(radius: radius); - - @override - TextInputStyle inputStyle(TextStyle? inputStyle) => - this(inputStyle: inputStyle); - - @override - TextInputStyle iconColor(Color? iconColor) => this(iconColor: iconColor); - - @override - TextInputStyle prefixStyle(TextStyle? prefixStyle) => - this(prefixStyle: prefixStyle); - - @override - TextInputStyle prefixIconColor(Color? prefixIconColor) => - this(prefixIconColor: prefixIconColor); - - @override - TextInputStyle suffixStyle(TextStyle? suffixStyle) => - this(suffixStyle: suffixStyle); - - @override - TextInputStyle suffixIconColor(Color? suffixIconColor) => - this(suffixIconColor: suffixIconColor); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TextInputStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// TextInputStyle(...).copyWith(id: 12, name: "My name") - /// ```` - TextInputStyle call({ - Object? labelStyle = const $CopyWithPlaceholder(), - Object? hintStyle = const $CopyWithPlaceholder(), - Object? backgroundColors = const $CopyWithPlaceholder(), - Object? borderColors = const $CopyWithPlaceholder(), - Object? boxShadow = const $CopyWithPlaceholder(), - Object? radius = const $CopyWithPlaceholder(), - Object? inputStyle = const $CopyWithPlaceholder(), - Object? iconColor = const $CopyWithPlaceholder(), - Object? prefixStyle = const $CopyWithPlaceholder(), - Object? prefixIconColor = const $CopyWithPlaceholder(), - Object? suffixStyle = const $CopyWithPlaceholder(), - Object? suffixIconColor = const $CopyWithPlaceholder(), - }) { - return TextInputStyle( - labelStyle: labelStyle == const $CopyWithPlaceholder() - ? _value.labelStyle - // ignore: cast_nullable_to_non_nullable - : labelStyle as TextStyle?, - hintStyle: hintStyle == const $CopyWithPlaceholder() - ? _value.hintStyle - // ignore: cast_nullable_to_non_nullable - : hintStyle as TextStyle?, - backgroundColors: backgroundColors == const $CopyWithPlaceholder() - ? _value.backgroundColors - // ignore: cast_nullable_to_non_nullable - : backgroundColors as MultiColor?, - borderColors: borderColors == const $CopyWithPlaceholder() - ? _value.borderColors - // ignore: cast_nullable_to_non_nullable - : borderColors as MultiColor?, - boxShadow: boxShadow == const $CopyWithPlaceholder() - ? _value.boxShadow - // ignore: cast_nullable_to_non_nullable - : boxShadow as BoxShadow?, - radius: radius == const $CopyWithPlaceholder() - ? _value.radius - // ignore: cast_nullable_to_non_nullable - : radius as BorderRadiusGeometry?, - inputStyle: inputStyle == const $CopyWithPlaceholder() - ? _value.inputStyle - // ignore: cast_nullable_to_non_nullable - : inputStyle as TextStyle?, - iconColor: iconColor == const $CopyWithPlaceholder() - ? _value.iconColor - // ignore: cast_nullable_to_non_nullable - : iconColor as Color?, - prefixStyle: prefixStyle == const $CopyWithPlaceholder() - ? _value.prefixStyle - // ignore: cast_nullable_to_non_nullable - : prefixStyle as TextStyle?, - prefixIconColor: prefixIconColor == const $CopyWithPlaceholder() - ? _value.prefixIconColor - // ignore: cast_nullable_to_non_nullable - : prefixIconColor as Color?, - suffixStyle: suffixStyle == const $CopyWithPlaceholder() - ? _value.suffixStyle - // ignore: cast_nullable_to_non_nullable - : suffixStyle as TextStyle?, - suffixIconColor: suffixIconColor == const $CopyWithPlaceholder() - ? _value.suffixIconColor - // ignore: cast_nullable_to_non_nullable - : suffixIconColor as Color?, - ); - } -} - -extension $TextInputStyleCopyWith on TextInputStyle { - /// Returns a callable class that can be used as follows: `instanceOfTextInputStyle.copyWith(...)` or like so:`instanceOfTextInputStyle.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$TextInputStyleCWProxy get copyWith => _$TextInputStyleCWProxyImpl(this); -} diff --git a/packages/wyatt_ui_components/pubspec.yaml b/packages/wyatt_ui_components/pubspec.yaml index 865b67f9..fbd278f1 100644 --- a/packages/wyatt_ui_components/pubspec.yaml +++ b/packages/wyatt_ui_components/pubspec.yaml @@ -10,7 +10,6 @@ environment: dependencies: flutter: { sdk: flutter } - copy_with_extension: ^5.0.0 wyatt_component_copy_with_extension: git: url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git @@ -19,7 +18,6 @@ dependencies: dev_dependencies: build_runner: ^2.3.3 - copy_with_extension_gen: ^5.0.0 flutter_test: { sdk: flutter } freezed: ^2.3.2 wyatt_analysis: -- 2.47.2 From 51672cc95ad83257a50577e36a4f606119adf0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 13:13:01 +0100 Subject: [PATCH 15/25] refactor(ui_components): move borderColors type --- .../src/domain/entities/text_inputs/text_input_style.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart index 72855a4e..6de90922 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart @@ -43,7 +43,7 @@ class TextInputStyle extends ThemeStyle { final Color? suffixIconColor; final MultiColor? backgroundColors; - final MultiColor? borderColors; + final Color? borderColors; final BoxShadow? boxShadow; final BorderRadiusGeometry? radius; final TextStyle? inputStyle; @@ -86,7 +86,7 @@ class TextInputStyle extends ThemeStyle { backgroundColors: MultiColor.lerp(a.backgroundColors, b.backgroundColors, t), radius: BorderRadiusGeometry.lerp(a.radius, b.radius, t), - borderColors: MultiColor.lerp(a.borderColors, b.borderColors, t), + borderColors: Color.lerp(a.borderColors, b.borderColors, t), boxShadow: BoxShadow.lerp(a.boxShadow, b.boxShadow, t), inputStyle: TextStyle.lerp(a.inputStyle, b.inputStyle, t), prefixStyle: TextStyle.lerp(a.prefixStyle, b.prefixStyle, t), @@ -106,7 +106,7 @@ class TextInputStyle extends ThemeStyle { TextStyle? labelStyle, TextStyle? hintStyle, MultiColor? backgroundColors, - MultiColor? borderColors, + Color? borderColors, BoxShadow? boxShadow, BorderRadiusGeometry? radius, TextStyle? inputStyle, -- 2.47.2 From f2b8c03dd7ea19c2696a965c56ab4fbcd80ef94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 13:15:47 +0100 Subject: [PATCH 16/25] refactor(ui_kit): update textinput component using borderColors as Color --- .../example/lib/theme/text_input_theme.dart | 36 +++++-------------- .../text_inputs/text_input_screen.dart | 9 ++--- .../text_input_theme_resolver.dart | 9 +++-- 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/packages/wyatt_ui_kit/example/lib/theme/text_input_theme.dart b/packages/wyatt_ui_kit/example/lib/theme/text_input_theme.dart index 93e583f4..63b6dc41 100644 --- a/packages/wyatt_ui_kit/example/lib/theme/text_input_theme.dart +++ b/packages/wyatt_ui_kit/example/lib/theme/text_input_theme.dart @@ -30,10 +30,7 @@ class TextInputTheme extends TextInputThemeExtension { factory TextInputTheme.light() => TextInputTheme( normalStyle: TextInputStyle( radius: BorderRadius.circular(12), - borderColors: const MultiColor([ - Color.fromRGBO(221, 224, 227, 1), - Color.fromRGBO(202, 204, 212, 1), - ]), + borderColors: const Color.fromRGBO(221, 224, 227, 1), labelStyle: GoogleFonts.montserrat( fontWeight: FontWeight.w300, color: const Color.fromRGBO(55, 65, 81, 1), @@ -45,10 +42,7 @@ class TextInputTheme extends TextInputThemeExtension { ), focusedStyle: TextInputStyle( radius: BorderRadius.circular(12), - borderColors: const MultiColor([ - Color.fromRGBO(60, 125, 251, 1), - Color.fromRGBO(68, 109, 244, 1), - ]), + borderColors: const Color.fromRGBO(60, 125, 251, 1), labelStyle: GoogleFonts.montserrat( fontWeight: FontWeight.w300, color: const Color.fromRGBO(55, 65, 81, 1), @@ -60,10 +54,7 @@ class TextInputTheme extends TextInputThemeExtension { ), errorStyle: TextInputStyle( radius: BorderRadius.circular(12), - borderColors: const MultiColor([ - Color.fromRGBO(251, 94, 60, 1), - Color.fromRGBO(244, 68, 100, 1), - ]), + borderColors: const Color.fromRGBO(244, 68, 100, 1), labelStyle: GoogleFonts.montserrat( fontWeight: FontWeight.w300, color: const Color.fromRGBO(244, 68, 100, 1), @@ -75,8 +66,7 @@ class TextInputTheme extends TextInputThemeExtension { ), disableStyle: TextInputStyle( radius: BorderRadius.circular(12), - borderColors: - const MultiColor.single(Color.fromRGBO(229, 231, 235, 1)), + borderColors: const Color.fromRGBO(229, 231, 235, 1), labelStyle: GoogleFonts.montserrat( fontWeight: FontWeight.w300, color: const Color.fromRGBO(156, 163, 175, 1), @@ -91,9 +81,7 @@ class TextInputTheme extends TextInputThemeExtension { factory TextInputTheme.dark() => TextInputTheme( normalStyle: TextInputStyle( radius: BorderRadius.circular(12), - borderColors: const MultiColor.single( - Color.fromRGBO(96, 101, 106, 1), - ), + borderColors: const Color.fromRGBO(96, 101, 106, 1), labelStyle: GoogleFonts.montserrat( fontWeight: FontWeight.w300, color: const Color.fromRGBO(204, 204, 204, 1), @@ -105,10 +93,7 @@ class TextInputTheme extends TextInputThemeExtension { ), focusedStyle: TextInputStyle( radius: BorderRadius.circular(12), - borderColors: const MultiColor([ - Color.fromRGBO(60, 125, 251, 1), - Color.fromRGBO(68, 109, 244, 1), - ]), + borderColors: const Color.fromRGBO(60, 125, 251, 1), labelStyle: GoogleFonts.montserrat( fontWeight: FontWeight.w300, color: const Color.fromRGBO(204, 204, 204, 1), @@ -120,10 +105,7 @@ class TextInputTheme extends TextInputThemeExtension { ), errorStyle: TextInputStyle( radius: BorderRadius.circular(12), - borderColors: const MultiColor([ - Color.fromRGBO(251, 94, 60, 1), - Color.fromRGBO(244, 68, 100, 1), - ]), + borderColors: const Color.fromRGBO(244, 68, 100, 1), labelStyle: GoogleFonts.montserrat( fontWeight: FontWeight.w300, color: const Color.fromRGBO(244, 68, 100, 1), @@ -135,9 +117,7 @@ class TextInputTheme extends TextInputThemeExtension { ), disableStyle: TextInputStyle( radius: BorderRadius.circular(12), - borderColors: const MultiColor.single( - Color.fromRGBO(96, 101, 106, 1), - ), + borderColors: const Color.fromRGBO(96, 101, 106, 1), labelStyle: GoogleFonts.montserrat( fontWeight: FontWeight.w300, color: const Color.fromRGBO(96, 101, 106, 1), diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart index 0766f8c0..f7b3945b 100644 --- a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart @@ -273,15 +273,10 @@ class TextInputScreen extends CubitScreen { ? style.backgroundColors?.color : null, borderRadius: style.radius ?? BorderRadius.circular(4), - border: (style.borderColors?.isGradient ?? false) || - (style.borderColors?.isColor ?? false) + border: (style.borderColors != null) ? Border.all( width: 1.5, - color: (style.borderColors?.isGradient ?? false) - ? style.borderColors!.colors.first - : (style.borderColors?.isColor ?? false) - ? style.borderColors!.color - : Colors.transparent, + color: style.borderColors!, ) : null, ), diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart index f421b762..62bd59f4 100644 --- a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart @@ -49,8 +49,7 @@ class TextInputThemeResolver extends ThemeResolver Date: Tue, 21 Feb 2023 13:19:11 +0100 Subject: [PATCH 17/25] fix(ui_kit): remove null check operator in Loader component --- .../wyatt_ui_kit/example/lib/loaders/loaders.dart | 3 +-- .../lib/src/components/loader/loader.dart | 5 ++--- .../src/components/loader/loader_theme_resolver.dart | 12 ++++++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/wyatt_ui_kit/example/lib/loaders/loaders.dart b/packages/wyatt_ui_kit/example/lib/loaders/loaders.dart index bc5d8945..cc456ae7 100644 --- a/packages/wyatt_ui_kit/example/lib/loaders/loaders.dart +++ b/packages/wyatt_ui_kit/example/lib/loaders/loaders.dart @@ -23,7 +23,7 @@ import 'package:wyatt_ui_kit_example/theme/constants.dart'; class Loaders extends DemoPage { const Loaders({super.key}); - + @override String get title => 'Loaders'; @@ -64,5 +64,4 @@ class Loaders extends DemoPage { const Gap(20), ], ); - } diff --git a/packages/wyatt_ui_kit/lib/src/components/loader/loader.dart b/packages/wyatt_ui_kit/lib/src/components/loader/loader.dart index a9379a3f..dd28e602 100644 --- a/packages/wyatt_ui_kit/lib/src/components/loader/loader.dart +++ b/packages/wyatt_ui_kit/lib/src/components/loader/loader.dart @@ -59,15 +59,14 @@ class Loader extends LoaderComponent with $LoaderCWMixin { final style = _resolve(context); final dimension = (radius != null) ? radius! * 2 : context.buttonTheme.height; - return SizedBox.square( dimension: dimension, child: RepaintBoundary( child: CustomPaint( painter: _LoaderPainter( - style.colors!, + style.colors ?? const MultiColor([]), dimension / 2, - style.stroke!, + style.stroke ?? 4, flip: flip ?? false, ), ) diff --git a/packages/wyatt_ui_kit/lib/src/components/loader/loader_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/loader/loader_theme_resolver.dart index 1b45ddaf..a5384e54 100644 --- a/packages/wyatt_ui_kit/lib/src/components/loader/loader_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/loader/loader_theme_resolver.dart @@ -24,6 +24,12 @@ class LoaderThemeResolver required this.customStyleFn, }); + @override + final LoaderStyle? Function( + BuildContext context, { + void extra, + }) customStyleFn; + /// Values taken from @override LoaderStyle computeDefaultValue( @@ -39,12 +45,6 @@ class LoaderThemeResolver stroke: 4, ); - @override - final LoaderStyle? Function( - BuildContext context, { - void extra, - }) customStyleFn; - @override LoaderStyle? computeExtensionValueFn( BuildContext context, -- 2.47.2 From 65379459467e9355014f37b283f73640f89fa8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 13:23:51 +0100 Subject: [PATCH 18/25] fix(ui_kit): remove null check operator in RichTextBuilder component --- .../lib/src/domain/entities/rich_text_builder/parser.dart | 4 ++-- .../src/components/rich_text_builder/rich_text_builder.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/parser.dart b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/parser.dart index bd92d252..b60684e4 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/parser.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/rich_text_builder/parser.dart @@ -23,7 +23,7 @@ class RichTextStyleParameter { this.styleName, ); - final TextStyle defaultStyle; + final TextStyle? defaultStyle; final Map definedStyle; final String? styleName; @@ -31,7 +31,7 @@ class RichTextStyleParameter { if (definedStyle.containsKey(styleName)) { return definedStyle[styleName]!; } - return defaultStyle; + return defaultStyle ?? const TextStyle(); } RichTextStyleParameter copyWith({ diff --git a/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder.dart b/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder.dart index 0ca1798a..c16df96c 100644 --- a/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder.dart +++ b/packages/wyatt_ui_kit/lib/src/components/rich_text_builder/rich_text_builder.dart @@ -59,7 +59,7 @@ class RichTextBuilder extends RichTextBuilderComponent text ?? '', regex, RichTextStyleParameter( - style.defaultStyle!, + style.defaultStyle, style.styles ?? {}, null, ), -- 2.47.2 From 25224469b5ad183cf0b3b29ee5892447fedcf79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 13:27:19 +0100 Subject: [PATCH 19/25] fix(ui_components): fix MultiColor lerp method --- .../wyatt_ui_components/lib/src/core/utils/multi_color.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart b/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart index 9e9b7222..d64ac9a3 100644 --- a/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart +++ b/packages/wyatt_ui_components/lib/src/core/utils/multi_color.dart @@ -64,12 +64,15 @@ class MultiColor { ); } else if (a.isGradient && b.isGradient) { final colors = List.empty(growable: true); - for (int i = 0; i < a.colors.length; i++) { + final shortestList = + (a.colors.length > b.colors.length) ? b.colors : a.colors; + for (int i = 0; i < shortestList.length; i++) { final lerpColor = Color.lerp(a.colors[i], b.colors[i], t); if (lerpColor != null) { colors.add(lerpColor); } } + return MultiColor(colors); } return b; } -- 2.47.2 From 133e0e910b3fe1da2d95f90cd0e4c7f51b34c086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 21 Feb 2023 13:34:04 +0100 Subject: [PATCH 20/25] fix(ui_kit): make card core stateless --- .../cards/widgets/card_background.dart | 51 +++++++++++ .../cards/widgets/card_wrapper.dart | 90 ++++++------------- 2 files changed, 78 insertions(+), 63 deletions(-) create mode 100644 packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_background.dart diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_background.dart b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_background.dart new file mode 100644 index 00000000..76862ab2 --- /dev/null +++ b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_background.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; + +class CardBackground extends StatefulWidget { + const CardBackground({super.key, this.background, this.cardKey}); + + final Widget? background; + final GlobalKey? cardKey; + + @override + State createState() => _CardBackgroundState(); +} + +class _CardBackgroundState extends State { + Size _cardSize = Size.zero; + + @override + void initState() { + super.initState(); + if (widget.background != null) { + WidgetsBinding.instance.addPostFrameCallback((_) { + _resizeCard(); + }); + } + } + + @override + void didUpdateWidget(covariant CardBackground oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.background != null) { + _resizeCard(); + } + } + + void _resizeCard() { + final RenderObject? renderBox = + widget.cardKey?.currentContext?.findRenderObject(); + if (renderBox != null) { + setState(() { + _cardSize = + Size(renderBox.paintBounds.width, renderBox.paintBounds.height); + }); + } + } + + @override + Widget build(BuildContext context) => SizedBox( + width: _cardSize.width, + height: _cardSize.height, + child: Center(child: widget.background), + ); +} diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart index 46a72582..db898c29 100644 --- a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart +++ b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart @@ -15,11 +15,12 @@ // along with this program. If not, see . import 'package:flutter/material.dart'; +import 'package:wyatt_ui_kit/src/components/cards/widgets/card_background.dart'; import 'package:wyatt_ui_kit/src/components/gradients/gradient_box_border.dart'; import 'package:wyatt_ui_kit/src/domain/card_theme_extension.dart'; -class CardWrapper extends StatefulWidget { - const CardWrapper({ +class CardWrapper extends StatelessWidget { + CardWrapper({ required this.child, required this.backgroundColors, required this.borderColors, @@ -40,54 +41,19 @@ class CardWrapper extends StatefulWidget { final Size? maxSize; final double? padding; - @override - State createState() => _CardWrapperState(); -} - -class _CardWrapperState extends State { - Size _cardSize = Size.zero; final GlobalKey _key = GlobalKey(); - @override - void initState() { - super.initState(); - if (widget.background != null) { - WidgetsBinding.instance.addPostFrameCallback((_) { - _resizeCard(); - }); - } - } - - @override - void didUpdateWidget(covariant CardWrapper oldWidget) { - super.didUpdateWidget(oldWidget); - if (widget.background != null) { - _resizeCard(); - } - } - - void _resizeCard() { - final RenderObject? renderBox = _key.currentContext?.findRenderObject(); - if (renderBox != null) { - setState(() { - _cardSize = - Size(renderBox.paintBounds.width, renderBox.paintBounds.height); - }); - } - } - - Widget _buildChild(Widget child) => (widget.background != null) + Widget _buildChild(Widget child) => (background != null) ? Stack( alignment: Alignment.center, children: [ - SizedBox( - width: _cardSize.width, - height: _cardSize.height, - child: Center(child: widget.background), + CardBackground( + cardKey: _key, + background: background, ), Padding( padding: EdgeInsets.all( - widget.padding ?? 25, + padding ?? 25, ), child: child, ), @@ -95,15 +61,14 @@ class _CardWrapperState extends State { ) : Padding( padding: EdgeInsets.all( - widget.padding ?? 25, + padding ?? 25, ), child: child, ); Gradient? _cardGradient(BuildContext context) { - if (widget.backgroundColors != null && - widget.backgroundColors!.length >= 2) { - return LinearGradient(colors: widget.backgroundColors!); + if (backgroundColors != null && backgroundColors!.length >= 2) { + return LinearGradient(colors: backgroundColors!); } else { final extensionCardColor = Theme.of(context).extension(); @@ -120,9 +85,8 @@ class _CardWrapperState extends State { } Color? _cardColor(BuildContext context) { - if (widget.backgroundColors != null && - widget.backgroundColors!.length == 1) { - return widget.backgroundColors!.first; + if (backgroundColors != null && backgroundColors!.length == 1) { + return backgroundColors!.first; } else { final extensionCardColor = Theme.of(context).extension(); @@ -136,16 +100,16 @@ class _CardWrapperState extends State { } BoxBorder? _boxBorder(BuildContext context) { - if (widget.borderColors != null) { - if (widget.borderColors!.length >= 2) { + if (borderColors != null) { + if (borderColors!.length >= 2) { return CustomGradientBoxBorder( gradient: LinearGradient( - colors: widget.borderColors!, + colors: borderColors!, ), ); - } else if (widget.borderColors!.isNotEmpty) { + } else if (borderColors!.isNotEmpty) { return Border.all( - color: widget.borderColors!.first, + color: borderColors!.first, ); } } else { @@ -171,8 +135,8 @@ class _CardWrapperState extends State { List _shadow(BuildContext context) { final shadows = List.empty(growable: true); - if (widget.shadow != null) { - shadows.add(widget.shadow!); + if (shadow != null) { + shadows.add(shadow!); } else { final extensionCardColor = Theme.of(context).extension(); @@ -195,17 +159,17 @@ class _CardWrapperState extends State { border: _boxBorder(context), boxShadow: _shadow(context), ), - child: (widget.minSize != null && widget.maxSize != null) + child: (minSize != null && maxSize != null) ? ConstrainedBox( constraints: BoxConstraints( - minWidth: widget.minSize!.width, - minHeight: widget.minSize!.height, - maxWidth: widget.maxSize!.width, - maxHeight: widget.maxSize!.height, + minWidth: minSize!.width, + minHeight: minSize!.height, + maxWidth: maxSize!.width, + maxHeight: maxSize!.height, ), - child: _buildChild(widget.child), + child: _buildChild(child), ) - : _buildChild(widget.child), + : _buildChild(child), ), ); } -- 2.47.2 From b077f4baf05912b6f9691f4ccb0aad7c2a723d3d Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Tue, 21 Feb 2023 15:07:56 +0100 Subject: [PATCH 21/25] refactor(ui_kit): rename GradientBoxBorder --- .../components/buttons/flat_button/flat_button_screen.dart | 2 +- .../buttons/simple_icon_button/simple_icon_screen.dart | 2 +- .../buttons/symbol_button/symbol_button_screen.dart | 2 +- .../lib/src/components/cards/widgets/card_wrapper.dart | 4 ++-- .../lib/src/components/gradients/gradient_box_border.dart | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) 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 14b739fa..6be53168 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 @@ -121,7 +121,7 @@ class FlatButtonScreen extends CubitScreen { // If no border color => no default value border: (style.borderColors != null && style.stroke != null) ? (style.borderColors?.isGradient ?? false) - ? CustomGradientBoxBorder( + ? GradientBoxBorder( gradient: LinearGradient( colors: style.borderColors!.colors, ), 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 624cfccc..4467cd54 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 @@ -120,7 +120,7 @@ class SimpleIconButtonScreen extends CubitScreen { // If no border color => no default value border: (style.borderColors != null && style.stroke != null) ? (style.borderColors?.isGradient ?? false) - ? CustomGradientBoxBorder( + ? GradientBoxBorder( gradient: LinearGradient( colors: style.borderColors!.colors, ), 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 6b586d82..be5009db 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 @@ -144,7 +144,7 @@ class SymbolButtonScreen border: (style.borderColors != null && style.stroke != null) ? (style.borderColors?.isGradient ?? false) - ? CustomGradientBoxBorder( + ? GradientBoxBorder( gradient: LinearGradient( colors: style.borderColors!.colors, ), diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart index db898c29..75473d0b 100644 --- a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart +++ b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart @@ -102,7 +102,7 @@ class CardWrapper extends StatelessWidget { BoxBorder? _boxBorder(BuildContext context) { if (borderColors != null) { if (borderColors!.length >= 2) { - return CustomGradientBoxBorder( + return GradientBoxBorder( gradient: LinearGradient( colors: borderColors!, ), @@ -118,7 +118,7 @@ class CardWrapper extends StatelessWidget { if (extensionCardColor != null && extensionCardColor.borderColors != null) { if (extensionCardColor.borderColors!.isGradient) { - return CustomGradientBoxBorder( + return GradientBoxBorder( gradient: LinearGradient( colors: extensionCardColor.borderColors!.colors, ), diff --git a/packages/wyatt_ui_kit/lib/src/components/gradients/gradient_box_border.dart b/packages/wyatt_ui_kit/lib/src/components/gradients/gradient_box_border.dart index 10372a96..2a77264e 100644 --- a/packages/wyatt_ui_kit/lib/src/components/gradients/gradient_box_border.dart +++ b/packages/wyatt_ui_kit/lib/src/components/gradients/gradient_box_border.dart @@ -17,8 +17,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/painting.dart'; -class CustomGradientBoxBorder extends Border { - const CustomGradientBoxBorder({this.gradient, this.width = 1}); +class GradientBoxBorder extends Border { + const GradientBoxBorder({this.gradient, this.width = 1}); final Gradient? gradient; final double width; -- 2.47.2 From 5906d54aad225b2b624310e45231e0e1e341718f Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Tue, 21 Feb 2023 15:08:24 +0100 Subject: [PATCH 22/25] build(ui_component): remove freezed --- packages/wyatt_ui_components/pubspec.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/wyatt_ui_components/pubspec.yaml b/packages/wyatt_ui_components/pubspec.yaml index fbd278f1..80e5e707 100644 --- a/packages/wyatt_ui_components/pubspec.yaml +++ b/packages/wyatt_ui_components/pubspec.yaml @@ -14,12 +14,10 @@ dependencies: git: url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git path: packages/wyatt_component_copy_with_extension - freezed_annotation: ^2.2.0 dev_dependencies: build_runner: ^2.3.3 flutter_test: { sdk: flutter } - freezed: ^2.3.2 wyatt_analysis: hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub version: ^2.4.0 -- 2.47.2 From 12d04c91eddd6e20ce5b983922f1bf7b2309de10 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Tue, 21 Feb 2023 15:17:05 +0100 Subject: [PATCH 23/25] fix(ui): use multicolor in cards --- .../domain/entities/cards/card_component.dart | 5 ++-- .../cards/information_card_component.g.dart | 8 +++--- .../cards/portfolio_card_component.g.dart | 8 +++--- .../cards/quote_card_component.g.dart | 8 +++--- .../cards/skill_card_component.g.dart | 8 +++--- .../information_card/information_card.g.dart | 8 +++--- .../portfolio_card/portfolio_card.g.dart | 8 +++--- .../cards/quote_card/quote_card.g.dart | 8 +++--- .../cards/skill_card/skill_card.g.dart | 8 +++--- .../cards/widgets/card_wrapper.dart | 26 +++++++++---------- .../lib/src/core/helpers/helpers.dart | 1 + .../lib/src/core/helpers/theme_helper.dart | 2 +- 12 files changed, 49 insertions(+), 49 deletions(-) diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/cards/card_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/cards/card_component.dart index bafc5c9a..2085f99c 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/cards/card_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/cards/card_component.dart @@ -15,6 +15,7 @@ // along with this program. If not, see . import 'package:flutter/widgets.dart'; +import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/domain/entities/component.dart'; abstract class CardComponent extends Component { @@ -41,10 +42,10 @@ abstract class CardComponent extends Component { final double? padding; /// Border gradient color (from left to right) - final List? borderColors; + final MultiColor? borderColors; /// Card background color - final List? backgroundColors; + final MultiColor? backgroundColors; /// Minimum size for this card final Size? minSize; diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/cards/information_card_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/cards/information_card_component.g.dart index 4802eb9e..59c9369e 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/cards/information_card_component.g.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/cards/information_card_component.g.dart @@ -14,8 +14,8 @@ abstract class $InformationCardComponentCWProxy { InformationCardComponent axis(Axis? axis); InformationCardComponent radius(double? radius); InformationCardComponent padding(double? padding); - InformationCardComponent borderColors(List? borderColors); - InformationCardComponent backgroundColors(List? backgroundColors); + InformationCardComponent borderColors(MultiColor? borderColors); + InformationCardComponent backgroundColors(MultiColor? backgroundColors); InformationCardComponent minSize(Size? minSize); InformationCardComponent maxSize(Size? maxSize); InformationCardComponent shadow(BoxShadow? shadow); @@ -29,8 +29,8 @@ abstract class $InformationCardComponentCWProxy { Axis? axis, double? radius, double? padding, - List? borderColors, - List? backgroundColors, + MultiColor? borderColors, + MultiColor? backgroundColors, Size? minSize, Size? maxSize, BoxShadow? shadow, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/cards/portfolio_card_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/cards/portfolio_card_component.g.dart index a21bd6bc..87ddefb6 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/cards/portfolio_card_component.g.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/cards/portfolio_card_component.g.dart @@ -19,8 +19,8 @@ abstract class $PortfolioCardComponentCWProxy { PortfolioCardComponent assets(List? assets); PortfolioCardComponent radius(double? radius); PortfolioCardComponent padding(double? padding); - PortfolioCardComponent borderColors(List? borderColors); - PortfolioCardComponent backgroundColors(List? backgroundColors); + PortfolioCardComponent borderColors(MultiColor? borderColors); + PortfolioCardComponent backgroundColors(MultiColor? backgroundColors); PortfolioCardComponent minSize(Size? minSize); PortfolioCardComponent maxSize(Size? maxSize); PortfolioCardComponent shadow(BoxShadow? shadow); @@ -38,8 +38,8 @@ abstract class $PortfolioCardComponentCWProxy { List? assets, double? radius, double? padding, - List? borderColors, - List? backgroundColors, + MultiColor? borderColors, + MultiColor? backgroundColors, Size? minSize, Size? maxSize, BoxShadow? shadow, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/cards/quote_card_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/cards/quote_card_component.g.dart index 0ce84883..cef1cb7d 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/cards/quote_card_component.g.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/cards/quote_card_component.g.dart @@ -16,8 +16,8 @@ abstract class $QuoteCardComponentCWProxy { QuoteCardComponent rightQuote(Widget? rightQuote); QuoteCardComponent radius(double? radius); QuoteCardComponent padding(double? padding); - QuoteCardComponent borderColors(List? borderColors); - QuoteCardComponent backgroundColors(List? backgroundColors); + QuoteCardComponent borderColors(MultiColor? borderColors); + QuoteCardComponent backgroundColors(MultiColor? backgroundColors); QuoteCardComponent minSize(Size? minSize); QuoteCardComponent maxSize(Size? maxSize); QuoteCardComponent shadow(BoxShadow? shadow); @@ -33,8 +33,8 @@ abstract class $QuoteCardComponentCWProxy { Widget? rightQuote, double? radius, double? padding, - List? borderColors, - List? backgroundColors, + MultiColor? borderColors, + MultiColor? backgroundColors, Size? minSize, Size? maxSize, BoxShadow? shadow, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/cards/skill_card_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/cards/skill_card_component.g.dart index a69c819d..86094931 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/cards/skill_card_component.g.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/cards/skill_card_component.g.dart @@ -17,8 +17,8 @@ abstract class $SkillCardComponentCWProxy { Color? secondaryBackgroundColors); SkillCardComponent radius(double? radius); SkillCardComponent padding(double? padding); - SkillCardComponent borderColors(List? borderColors); - SkillCardComponent backgroundColors(List? backgroundColors); + SkillCardComponent borderColors(MultiColor? borderColors); + SkillCardComponent backgroundColors(MultiColor? backgroundColors); SkillCardComponent minSize(Size? minSize); SkillCardComponent maxSize(Size? maxSize); SkillCardComponent shadow(BoxShadow? shadow); @@ -34,8 +34,8 @@ abstract class $SkillCardComponentCWProxy { Color? secondaryBackgroundColors, double? radius, double? padding, - List? borderColors, - List? backgroundColors, + MultiColor? borderColors, + MultiColor? backgroundColors, Size? minSize, Size? maxSize, BoxShadow? shadow, diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/information_card/information_card.g.dart b/packages/wyatt_ui_kit/lib/src/components/cards/information_card/information_card.g.dart index 1378d99c..16365148 100644 --- a/packages/wyatt_ui_kit/lib/src/components/cards/information_card/information_card.g.dart +++ b/packages/wyatt_ui_kit/lib/src/components/cards/information_card/information_card.g.dart @@ -24,10 +24,10 @@ class $InformationCardCWProxyImpl implements $InformationCardComponentCWProxy { @override InformationCard padding(double? padding) => this(padding: padding); @override - InformationCard borderColors(List? borderColors) => + InformationCard borderColors(MultiColor? borderColors) => this(borderColors: borderColors); @override - InformationCard backgroundColors(List? backgroundColors) => + InformationCard backgroundColors(MultiColor? backgroundColors) => this(backgroundColors: backgroundColors); @override InformationCard minSize(Size? minSize) => this(minSize: minSize); @@ -49,8 +49,8 @@ class $InformationCardCWProxyImpl implements $InformationCardComponentCWProxy { Axis? axis, double? radius, double? padding, - List? borderColors, - List? backgroundColors, + MultiColor? borderColors, + MultiColor? backgroundColors, Size? minSize, Size? maxSize, BoxShadow? shadow, diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/portfolio_card/portfolio_card.g.dart b/packages/wyatt_ui_kit/lib/src/components/cards/portfolio_card/portfolio_card.g.dart index 0142a408..735f8f58 100644 --- a/packages/wyatt_ui_kit/lib/src/components/cards/portfolio_card/portfolio_card.g.dart +++ b/packages/wyatt_ui_kit/lib/src/components/cards/portfolio_card/portfolio_card.g.dart @@ -36,10 +36,10 @@ class $PortfolioCardCWProxyImpl implements $PortfolioCardComponentCWProxy { @override PortfolioCard padding(double? padding) => this(padding: padding); @override - PortfolioCard borderColors(List? borderColors) => + PortfolioCard borderColors(MultiColor? borderColors) => this(borderColors: borderColors); @override - PortfolioCard backgroundColors(List? backgroundColors) => + PortfolioCard backgroundColors(MultiColor? backgroundColors) => this(backgroundColors: backgroundColors); @override PortfolioCard minSize(Size? minSize) => this(minSize: minSize); @@ -64,8 +64,8 @@ class $PortfolioCardCWProxyImpl implements $PortfolioCardComponentCWProxy { List? assets, double? radius, double? padding, - List? borderColors, - List? backgroundColors, + MultiColor? borderColors, + MultiColor? backgroundColors, Size? minSize, Size? maxSize, BoxShadow? shadow, diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/quote_card/quote_card.g.dart b/packages/wyatt_ui_kit/lib/src/components/cards/quote_card/quote_card.g.dart index 548c0088..90c7d5f2 100644 --- a/packages/wyatt_ui_kit/lib/src/components/cards/quote_card/quote_card.g.dart +++ b/packages/wyatt_ui_kit/lib/src/components/cards/quote_card/quote_card.g.dart @@ -28,10 +28,10 @@ class $QuoteCardCWProxyImpl implements $QuoteCardComponentCWProxy { @override QuoteCard padding(double? padding) => this(padding: padding); @override - QuoteCard borderColors(List? borderColors) => + QuoteCard borderColors(MultiColor? borderColors) => this(borderColors: borderColors); @override - QuoteCard backgroundColors(List? backgroundColors) => + QuoteCard backgroundColors(MultiColor? backgroundColors) => this(backgroundColors: backgroundColors); @override QuoteCard minSize(Size? minSize) => this(minSize: minSize); @@ -54,8 +54,8 @@ class $QuoteCardCWProxyImpl implements $QuoteCardComponentCWProxy { Widget? rightQuote, double? radius, double? padding, - List? borderColors, - List? backgroundColors, + MultiColor? borderColors, + MultiColor? backgroundColors, Size? minSize, Size? maxSize, BoxShadow? shadow, diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/skill_card/skill_card.g.dart b/packages/wyatt_ui_kit/lib/src/components/cards/skill_card/skill_card.g.dart index 96f74491..e66fe9e2 100644 --- a/packages/wyatt_ui_kit/lib/src/components/cards/skill_card/skill_card.g.dart +++ b/packages/wyatt_ui_kit/lib/src/components/cards/skill_card/skill_card.g.dart @@ -31,10 +31,10 @@ class $SkillCardCWProxyImpl implements $SkillCardComponentCWProxy { @override SkillCard padding(double? padding) => this(padding: padding); @override - SkillCard borderColors(List? borderColors) => + SkillCard borderColors(MultiColor? borderColors) => this(borderColors: borderColors); @override - SkillCard backgroundColors(List? backgroundColors) => + SkillCard backgroundColors(MultiColor? backgroundColors) => this(backgroundColors: backgroundColors); @override SkillCard minSize(Size? minSize) => this(minSize: minSize); @@ -57,8 +57,8 @@ class $SkillCardCWProxyImpl implements $SkillCardComponentCWProxy { Color? secondaryBackgroundColors, double? radius, double? padding, - List? borderColors, - List? backgroundColors, + MultiColor? borderColors, + MultiColor? backgroundColors, Size? minSize, Size? maxSize, BoxShadow? shadow, diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart index 75473d0b..c2b91ca4 100644 --- a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart +++ b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart @@ -15,9 +15,9 @@ // along with this program. If not, see . import 'package:flutter/material.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_kit/src/components/cards/widgets/card_background.dart'; -import 'package:wyatt_ui_kit/src/components/gradients/gradient_box_border.dart'; -import 'package:wyatt_ui_kit/src/domain/card_theme_extension.dart'; +import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; class CardWrapper extends StatelessWidget { CardWrapper({ @@ -34,8 +34,8 @@ class CardWrapper extends StatelessWidget { final Widget? background; final Widget child; - final List? backgroundColors; - final List? borderColors; + final MultiColor? backgroundColors; + final MultiColor? borderColors; final BoxShadow? shadow; final Size? minSize; final Size? maxSize; @@ -67,8 +67,8 @@ class CardWrapper extends StatelessWidget { ); Gradient? _cardGradient(BuildContext context) { - if (backgroundColors != null && backgroundColors!.length >= 2) { - return LinearGradient(colors: backgroundColors!); + if (backgroundColors != null && backgroundColors!.isGradient) { + return LinearGradientHelper.fromMultiColor(backgroundColors!); } else { final extensionCardColor = Theme.of(context).extension(); @@ -85,8 +85,8 @@ class CardWrapper extends StatelessWidget { } Color? _cardColor(BuildContext context) { - if (backgroundColors != null && backgroundColors!.length == 1) { - return backgroundColors!.first; + if (backgroundColors != null && backgroundColors!.isColor) { + return backgroundColors!.color; } else { final extensionCardColor = Theme.of(context).extension(); @@ -101,15 +101,13 @@ class CardWrapper extends StatelessWidget { BoxBorder? _boxBorder(BuildContext context) { if (borderColors != null) { - if (borderColors!.length >= 2) { + if (borderColors!.isGradient) { return GradientBoxBorder( - gradient: LinearGradient( - colors: borderColors!, - ), + gradient: LinearGradientHelper.fromMultiColor(borderColors!), ); - } else if (borderColors!.isNotEmpty) { + } else if (borderColors!.isColor) { return Border.all( - color: borderColors!.first, + color: borderColors!.color, ); } } else { diff --git a/packages/wyatt_ui_kit/lib/src/core/helpers/helpers.dart b/packages/wyatt_ui_kit/lib/src/core/helpers/helpers.dart index 35d48e7f..0e95fe99 100644 --- a/packages/wyatt_ui_kit/lib/src/core/helpers/helpers.dart +++ b/packages/wyatt_ui_kit/lib/src/core/helpers/helpers.dart @@ -15,3 +15,4 @@ // along with this program. If not, see . export './linear_gradient_helper.dart'; +export './theme_helper.dart'; diff --git a/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart b/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart index f5164d65..5414bfce 100644 --- a/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart +++ b/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with super program. If not, see . -class ThemeHelper { +abstract class ThemeHelper { static T? getThemeElement( List? styles, { required T? Function(P?)? transform, -- 2.47.2 From 93cc5058d1cee78c53528964aed4debb8baa2830 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Tue, 21 Feb 2023 15:37:42 +0100 Subject: [PATCH 24/25] refactor(ui_kit): use ThemeHelper in cards --- .../cards/widgets/card_wrapper.dart | 137 ++++++++---------- .../lib/src/core/helpers/theme_helper.dart | 8 + 2 files changed, 65 insertions(+), 80 deletions(-) diff --git a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart index c2b91ca4..aed05cae 100644 --- a/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart +++ b/packages/wyatt_ui_kit/lib/src/components/cards/widgets/card_wrapper.dart @@ -66,84 +66,17 @@ class CardWrapper extends StatelessWidget { child: child, ); - Gradient? _cardGradient(BuildContext context) { - if (backgroundColors != null && backgroundColors!.isGradient) { - return LinearGradientHelper.fromMultiColor(backgroundColors!); - } else { - final extensionCardColor = - Theme.of(context).extension(); - - if (extensionCardColor != null && - extensionCardColor.backgroundColors != null && - extensionCardColor.backgroundColors!.isGradient) { - return LinearGradient( - colors: extensionCardColor.backgroundColors!.colors, - ); - } - } - return null; - } - - Color? _cardColor(BuildContext context) { - if (backgroundColors != null && backgroundColors!.isColor) { - return backgroundColors!.color; - } else { - final extensionCardColor = - Theme.of(context).extension(); - - if (extensionCardColor != null && - extensionCardColor.backgroundColors != null) { - return extensionCardColor.backgroundColors!.color; - } - } - return Theme.of(context).cardColor; - } - - BoxBorder? _boxBorder(BuildContext context) { - if (borderColors != null) { - if (borderColors!.isGradient) { - return GradientBoxBorder( - gradient: LinearGradientHelper.fromMultiColor(borderColors!), - ); - } else if (borderColors!.isColor) { - return Border.all( - color: borderColors!.color, - ); - } - } else { - final extensionCardColor = - Theme.of(context).extension(); - if (extensionCardColor != null && - extensionCardColor.borderColors != null) { - if (extensionCardColor.borderColors!.isGradient) { - return GradientBoxBorder( - gradient: LinearGradient( - colors: extensionCardColor.borderColors!.colors, - ), - ); - } else if (extensionCardColor.backgroundColors!.colors.isNotEmpty) { - return Border.all( - color: extensionCardColor.backgroundColors!.color, - ); - } - } - } - return null; - } - List _shadow(BuildContext context) { - final shadows = List.empty(growable: true); - if (shadow != null) { - shadows.add(shadow!); - } else { - final extensionCardColor = - Theme.of(context).extension(); - if (extensionCardColor != null && - extensionCardColor.shadowColor != null) { - shadows.add(extensionCardColor.shadowColor!); - } - } - return shadows; + final themeShadow = ThemeHelper.getThemeElement( + [ + shadow, + Theme.of(context).extension()?.shadowColor, + ], + valueValidator: (shadow) => shadow != null, + transform: (shadow) => shadow, + defaultValue: null, + ); + return (themeShadow != null) ? [themeShadow] : []; } @override @@ -152,9 +85,53 @@ class CardWrapper extends StatelessWidget { key: _key, decoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(12)), - gradient: _cardGradient(context), - color: _cardColor(context), - border: _boxBorder(context), + gradient: ThemeHelper.getThemeElement( + [ + backgroundColors, + Theme.of(context) + .extension() + ?.backgroundColors, + ], + valueValidator: (multiColor) => + multiColor != null && multiColor.isGradient, + transform: (multiColor) => + LinearGradientHelper.fromMultiColor(multiColor!), + defaultValue: null, + ), + color: ThemeHelper.getThemeElement( + [ + backgroundColors, + Theme.of(context) + .extension() + ?.backgroundColors, + ], + valueValidator: (multiColor) => + multiColor != null && multiColor.isColor, + transform: (multiColor) => multiColor?.color, + defaultValue: Theme.of(context).cardColor, + ), + border: ThemeHelper.getThemeElement( + [ + borderColors, + Theme.of(context).extension()?.borderColors, + Theme.of(context) + .extension() + ?.backgroundColors, + ], + valueValidator: (multiColor) => + multiColor != null && multiColor.isColor, + transform: (multiColor) { + if (multiColor!.isGradient) { + return GradientBoxBorder( + gradient: LinearGradientHelper.fromMultiColor(multiColor), + ); + } + return Border.all( + color: multiColor.color, + ); + }, + defaultValue: null, + ), boxShadow: _shadow(context), ), child: (minSize != null && maxSize != null) diff --git a/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart b/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart index 5414bfce..79cb54c8 100644 --- a/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart +++ b/packages/wyatt_ui_kit/lib/src/core/helpers/theme_helper.dart @@ -14,7 +14,15 @@ // You should have received a copy of the GNU General Public License // along with super program. If not, see . +/// A helper class for getting theme elements. abstract class ThemeHelper { + + /// Gets a theme element from a list of styles. + /// Styles are checked in order, and the first one that passes the + /// [valueValidator] is returned. + /// If no style passes the [valueValidator], the [defaultValue] is returned. + /// If [styles] is null or empty, the [defaultValue] is returned. + /// Style elements are transformed using the [transform] function. static T? getThemeElement( List? styles, { required T? Function(P?)? transform, -- 2.47.2 From 6037e13f502f00a13a10e976ed34d307aa237f5c Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Tue, 21 Feb 2023 16:08:23 +0100 Subject: [PATCH 25/25] fix(ui_component): inverse merge in TextInputStyle --- .../text_inputs/text_input_style.dart | 26 +++++++++---------- .../text_inputs/text_input_screen.dart | 5 ---- .../text_input_theme_resolver.dart | 11 -------- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart index 6de90922..7849eb19 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/text_inputs/text_input_style.dart @@ -55,19 +55,19 @@ class TextInputStyle extends ThemeStyle { if (a == null) { return b.copyWith(); } - return b.copyWith( - labelStyle: a.labelStyle, - hintStyle: a.hintStyle, - backgroundColors: a.backgroundColors, - borderColors: a.borderColors, - boxShadow: a.boxShadow, - radius: a.radius, - inputStyle: a.inputStyle, - iconColor: a.iconColor, - prefixStyle: a.prefixStyle, - prefixIconColor: a.prefixIconColor, - suffixIconColor: a.suffixIconColor, - suffixStyle: a.suffixStyle, + return a.copyWith( + labelStyle: b.labelStyle, + hintStyle: b.hintStyle, + backgroundColors: b.backgroundColors, + borderColors: b.borderColors, + boxShadow: b.boxShadow, + radius: b.radius, + inputStyle: b.inputStyle, + iconColor: b.iconColor, + prefixStyle: b.prefixStyle, + prefixIconColor: b.prefixIconColor, + suffixIconColor: b.suffixIconColor, + suffixStyle: b.suffixStyle, ); } diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart index f7b3945b..bc109d98 100644 --- a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_screen.dart @@ -208,9 +208,7 @@ class TextInputScreen extends CubitScreen { textInputStyle = normalStyle; break; case ControlState.hovered: - break; case ControlState.tapped: - break; case null: break; } @@ -221,11 +219,8 @@ class TextInputScreen extends CubitScreen { style = errorStyle; break; case StatusState.initial: - break; case StatusState.success: - break; case StatusState.loading: - break; case null: break; } diff --git a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart index 62bd59f4..5a3fbd0c 100644 --- a/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart +++ b/packages/wyatt_ui_kit/lib/src/components/text_inputs/text_input_theme_resolver.dart @@ -81,11 +81,8 @@ class TextInputThemeResolver extends ThemeResolver