From 9c8aa8ef2c96f8688a2994d4549c7ba59c562347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Wed, 8 Feb 2023 17:42:33 +0100 Subject: [PATCH] feat(ui_components): add text wrapper instead of String/Widget for Texts --- .../lib/components/custom_app_bar.dart | 4 ++- .../lib/components/custom_app_bar.g.dart | 4 +-- .../lib/components/custom_error_widget.dart | 2 +- .../lib/components/custom_error_widget.g.dart | 4 +-- .../lib/src/core/core.dart | 2 ++ .../lib/src/core/utils/text_wrapper.dart | 26 +++++++++++++++++++ .../domain/entities/app_bar_component.dart | 5 ++-- .../domain/entities/app_bar_component.g.dart | 4 +-- .../cards/information_card_component.dart | 12 ++++----- .../cards/information_card_component.g.dart | 12 ++++----- .../entities/cards/quote_card_component.dart | 14 +++++----- .../cards/quote_card_component.g.dart | 12 ++++----- .../entities/error_widget_component.dart | 5 ++-- .../entities/error_widget_component.g.dart | 4 +-- 14 files changed, 69 insertions(+), 41 deletions(-) create mode 100644 packages/wyatt_ui_components/lib/src/core/utils/text_wrapper.dart diff --git a/packages/wyatt_ui_components/example/lib/components/custom_app_bar.dart b/packages/wyatt_ui_components/example/lib/components/custom_app_bar.dart index 924281cb..95110dd8 100644 --- a/packages/wyatt_ui_components/example/lib/components/custom_app_bar.dart +++ b/packages/wyatt_ui_components/example/lib/components/custom_app_bar.dart @@ -10,6 +10,8 @@ class CustomAppBar extends AppBarComponent with $CustomAppBarCWMixin { @override Widget build(BuildContext context) => AppBar( - title: Text(super.title ?? ''), + title: Text( + super.title?.text ?? '', + ), ); } diff --git a/packages/wyatt_ui_components/example/lib/components/custom_app_bar.g.dart b/packages/wyatt_ui_components/example/lib/components/custom_app_bar.g.dart index 89c78122..2fd0319a 100644 --- a/packages/wyatt_ui_components/example/lib/components/custom_app_bar.g.dart +++ b/packages/wyatt_ui_components/example/lib/components/custom_app_bar.g.dart @@ -10,7 +10,7 @@ class $CustomAppBarCWProxyImpl implements $AppBarComponentCWProxy { const $CustomAppBarCWProxyImpl(this._value); final CustomAppBar _value; @override - CustomAppBar title(String? title) => this(title: title); + CustomAppBar title(TextWrapper? title) => this(title: title); @override CustomAppBar leading(Widget? leading) => this(leading: leading); @override @@ -19,7 +19,7 @@ class $CustomAppBarCWProxyImpl implements $AppBarComponentCWProxy { CustomAppBar key(Key? key) => this(key: key); @override CustomAppBar call({ - String? title, + TextWrapper? title, Widget? leading, List? actions, Key? key, diff --git a/packages/wyatt_ui_components/example/lib/components/custom_error_widget.dart b/packages/wyatt_ui_components/example/lib/components/custom_error_widget.dart index 450cf851..b0336e29 100644 --- a/packages/wyatt_ui_components/example/lib/components/custom_error_widget.dart +++ b/packages/wyatt_ui_components/example/lib/components/custom_error_widget.dart @@ -12,6 +12,6 @@ class CustomErrorWidget extends ErrorWidgetComponent @override Widget build(BuildContext context) => ColoredBox( color: Colors.red, - child: Center(child: Text(error ?? 'Error')), + child: Center(child: Text(error?.text ?? 'Error')), ); } diff --git a/packages/wyatt_ui_components/example/lib/components/custom_error_widget.g.dart b/packages/wyatt_ui_components/example/lib/components/custom_error_widget.g.dart index 67f26fcf..ae1e64dd 100644 --- a/packages/wyatt_ui_components/example/lib/components/custom_error_widget.g.dart +++ b/packages/wyatt_ui_components/example/lib/components/custom_error_widget.g.dart @@ -10,12 +10,12 @@ class $CustomErrorWidgetCWProxyImpl implements $ErrorWidgetComponentCWProxy { const $CustomErrorWidgetCWProxyImpl(this._value); final CustomErrorWidget _value; @override - CustomErrorWidget error(String? error) => this(error: error); + CustomErrorWidget error(TextWrapper? error) => this(error: error); @override CustomErrorWidget key(Key? key) => this(key: key); @override CustomErrorWidget call({ - String? error, + TextWrapper? error, Key? key, }) => CustomErrorWidget( diff --git a/packages/wyatt_ui_components/lib/src/core/core.dart b/packages/wyatt_ui_components/lib/src/core/core.dart index 243dd3d2..dd4b140f 100644 --- a/packages/wyatt_ui_components/lib/src/core/core.dart +++ b/packages/wyatt_ui_components/lib/src/core/core.dart @@ -15,3 +15,5 @@ // along with this program. If not, see . export 'extensions/build_context_extensions.dart'; +export 'mixins/copy_with_mixin.dart'; +export 'utils/text_wrapper.dart'; diff --git a/packages/wyatt_ui_components/lib/src/core/utils/text_wrapper.dart b/packages/wyatt_ui_components/lib/src/core/utils/text_wrapper.dart new file mode 100644 index 00000000..d3ce5513 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/core/utils/text_wrapper.dart @@ -0,0 +1,26 @@ +// 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'; + +class TextWrapper { + TextWrapper(this.text, {this.style}); + + factory TextWrapper.text(String text) => TextWrapper(text); + + final String text; + final TextStyle? style; +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/app_bar_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/app_bar_component.dart index be5dc624..4345b741 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/app_bar_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/app_bar_component.dart @@ -16,8 +16,7 @@ import 'package:flutter/material.dart'; import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; -import 'package:wyatt_ui_components/src/core/mixins/copy_with_mixin.dart'; -import 'package:wyatt_ui_components/src/domain/entities/component.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; part 'app_bar_component.g.dart'; @@ -30,7 +29,7 @@ abstract class AppBarComponent extends Component this.actions, super.key, }); - final String? title; + final TextWrapper? title; final Widget? leading; final List? actions; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/app_bar_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/app_bar_component.g.dart index fe0b0b20..e16ec248 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/app_bar_component.g.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/app_bar_component.g.dart @@ -7,12 +7,12 @@ part of 'app_bar_component.dart'; // ************************************************************************** abstract class $AppBarComponentCWProxy { - AppBarComponent title(String? title); + AppBarComponent title(TextWrapper? title); AppBarComponent leading(Widget? leading); AppBarComponent actions(List? actions); AppBarComponent key(Key? key); AppBarComponent call({ - String? title, + TextWrapper? title, Widget? leading, List? actions, Key? key, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/cards/information_card_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/cards/information_card_component.dart index 2af68c67..614729a2 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/cards/information_card_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/cards/information_card_component.dart @@ -16,8 +16,8 @@ import 'package:flutter/widgets.dart'; import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; -import 'package:wyatt_ui_components/src/core/mixins/copy_with_mixin.dart'; import 'package:wyatt_ui_components/src/domain/entities/cards/card_component.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; part 'information_card_component.g.dart'; @@ -32,8 +32,8 @@ abstract class InformationCardComponent extends CardComponent this.axis = Axis.vertical, super.radius = 12, super.padding = 25, - super.borderColors = const [Color(0xFFDDE0E3), Color(0xFFCACCD4)], - super.backgroundColor = const Color(0xFFF6F6F6), + super.borderColors, + super.backgroundColor, super.minSize = const Size(330, 230), super.maxSize = const Size(330, 530), super.shadow = const BoxShadow( @@ -47,7 +47,7 @@ abstract class InformationCardComponent extends CardComponent final Axis? axis; final List? icons; - final Widget? title; - final Widget? subtitle; - final Widget? body; + final TextWrapper? title; + final TextWrapper? subtitle; + final TextWrapper? body; } 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 c5a3e0fb..b4387287 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 @@ -8,9 +8,9 @@ part of 'information_card_component.dart'; abstract class $InformationCardComponentCWProxy { InformationCardComponent icons(List? icons); - InformationCardComponent title(Widget? title); - InformationCardComponent subtitle(Widget? subtitle); - InformationCardComponent body(Widget? body); + InformationCardComponent title(TextWrapper? title); + InformationCardComponent subtitle(TextWrapper? subtitle); + InformationCardComponent body(TextWrapper? body); InformationCardComponent axis(Axis? axis); InformationCardComponent radius(double? radius); InformationCardComponent padding(double? padding); @@ -23,9 +23,9 @@ abstract class $InformationCardComponentCWProxy { InformationCardComponent key(Key? key); InformationCardComponent call({ List? icons, - Widget? title, - Widget? subtitle, - Widget? body, + TextWrapper? title, + TextWrapper? subtitle, + TextWrapper? body, Axis? axis, double? radius, double? padding, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/cards/quote_card_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/cards/quote_card_component.dart index c5ac26c7..e11f3502 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/cards/quote_card_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/cards/quote_card_component.dart @@ -16,8 +16,8 @@ import 'package:flutter/widgets.dart'; import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; -import 'package:wyatt_ui_components/src/core/mixins/copy_with_mixin.dart'; import 'package:wyatt_ui_components/src/domain/entities/cards/card_component.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; part 'quote_card_component.g.dart'; @@ -34,8 +34,8 @@ abstract class QuoteCardComponent extends CardComponent this.rightQuote, super.radius = 12, super.padding = 25, - super.borderColors = const [Color(0xFFDDE0E3), Color(0xFFCACCD4)], - super.backgroundColor = const Color(0xFFF6F6F6), + super.borderColors, + super.backgroundColor, super.minSize = const Size(330, 230), super.maxSize = const Size(330, 530), super.shadow = const BoxShadow( @@ -48,11 +48,11 @@ abstract class QuoteCardComponent extends CardComponent }); final Widget? avatar; - final Widget? name; - final Text? subtitle; - final Gradient? gradient; - final Widget? quote; + final TextWrapper? name; + final TextWrapper? subtitle; + final TextWrapper? quote; + final Gradient? gradient; final Widget? leftQuote; final Widget? rightQuote; } 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 9e7f4318..12dcf876 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 @@ -8,10 +8,10 @@ part of 'quote_card_component.dart'; abstract class $QuoteCardComponentCWProxy { QuoteCardComponent avatar(Widget? avatar); - QuoteCardComponent name(Widget? name); - QuoteCardComponent subtitle(Text? subtitle); + QuoteCardComponent name(TextWrapper? name); + QuoteCardComponent subtitle(TextWrapper? subtitle); QuoteCardComponent gradient(Gradient? gradient); - QuoteCardComponent quote(Widget? quote); + QuoteCardComponent quote(TextWrapper? quote); QuoteCardComponent leftQuote(Widget? leftQuote); QuoteCardComponent rightQuote(Widget? rightQuote); QuoteCardComponent radius(double? radius); @@ -25,10 +25,10 @@ abstract class $QuoteCardComponentCWProxy { QuoteCardComponent key(Key? key); QuoteCardComponent call({ Widget? avatar, - Widget? name, - Text? subtitle, + TextWrapper? name, + TextWrapper? subtitle, Gradient? gradient, - Widget? quote, + TextWrapper? quote, Widget? leftQuote, Widget? rightQuote, double? radius, diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/error_widget_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/error_widget_component.dart index c896417a..bba5c1c6 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/error_widget_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/error_widget_component.dart @@ -16,8 +16,7 @@ import 'package:flutter/material.dart'; import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; -import 'package:wyatt_ui_components/src/core/mixins/copy_with_mixin.dart'; -import 'package:wyatt_ui_components/src/domain/entities/component.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; part 'error_widget_component.g.dart'; @@ -25,5 +24,5 @@ part 'error_widget_component.g.dart'; abstract class ErrorWidgetComponent extends Component with CopyWithMixin<$ErrorWidgetComponentCWProxy> { const ErrorWidgetComponent({required this.error, super.key}); - final String? error; + final TextWrapper? error; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/error_widget_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/error_widget_component.g.dart index 6d62b709..c7dba4d6 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/error_widget_component.g.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/error_widget_component.g.dart @@ -7,10 +7,10 @@ part of 'error_widget_component.dart'; // ************************************************************************** abstract class $ErrorWidgetComponentCWProxy { - ErrorWidgetComponent error(String? error); + ErrorWidgetComponent error(TextWrapper? error); ErrorWidgetComponent key(Key? key); ErrorWidgetComponent call({ - String? error, + TextWrapper? error, Key? key, }); }