From efa7ca09dd0f319a6b847bd0667fac5e030efd5c Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Thu, 9 Feb 2023 18:08:03 +0100 Subject: [PATCH] feat(ui_component): add string extension to easely wrap text --- .../wyatt_ui_components/example/lib/main.dart | 25 ++++++++++--------- .../lib/src/core/core.dart | 1 + .../src/core/extensions/string_extension.dart | 23 +++++++++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 packages/wyatt_ui_components/lib/src/core/extensions/string_extension.dart diff --git a/packages/wyatt_ui_components/example/lib/main.dart b/packages/wyatt_ui_components/example/lib/main.dart index 2ee31aeb..d49b551b 100644 --- a/packages/wyatt_ui_components/example/lib/main.dart +++ b/packages/wyatt_ui_components/example/lib/main.dart @@ -28,17 +28,17 @@ class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) => ComponentTheme( - componentThemeWidget: AppThemeComponent.components, - child: MaterialApp( - title: 'Wyatt Ui Components Example', - theme: ThemeData( - primarySwatch: Colors.blue, + componentThemeWidget: AppThemeComponent.components, + child: MaterialApp( + title: 'Wyatt Ui Components Example', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: const Scaffold( + body: Home(), + ), ), - home: const Scaffold( - body: Home(), - ), - ), - ); + ); } class Home extends StatelessWidget { @@ -48,14 +48,15 @@ class Home extends StatelessWidget { Widget build(BuildContext context) => Scaffold( appBar: PreferredSize( preferredSize: const Size.fromHeight(60), - child: context.components.appBar?.copyWith.title('Example title') ?? + child: context.components.appBar?.copyWith + .title('Example title'.wrap()) ?? const SizedBox.shrink(), ), body: Column( children: [ Expanded( child: context.components.errorWidget - ?.copyWith(error: 'Example erreur') ?? + ?.copyWith(error: 'Example erreur'.wrap()) ?? const SizedBox.shrink(), ), const SizedBox( diff --git a/packages/wyatt_ui_components/lib/src/core/core.dart b/packages/wyatt_ui_components/lib/src/core/core.dart index dd4b140f..079c0687 100644 --- a/packages/wyatt_ui_components/lib/src/core/core.dart +++ b/packages/wyatt_ui_components/lib/src/core/core.dart @@ -15,5 +15,6 @@ // along with this program. If not, see . export 'extensions/build_context_extensions.dart'; +export 'extensions/string_extension.dart'; export 'mixins/copy_with_mixin.dart'; export 'utils/text_wrapper.dart'; diff --git a/packages/wyatt_ui_components/lib/src/core/extensions/string_extension.dart b/packages/wyatt_ui_components/lib/src/core/extensions/string_extension.dart new file mode 100644 index 00000000..d0e7817e --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/core/extensions/string_extension.dart @@ -0,0 +1,23 @@ +// 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/widgets.dart'; +import 'package:wyatt_ui_components/src/core/utils/text_wrapper.dart'; + +extension StringExtension on String? { + TextWrapper? wrap({TextStyle? style}) => + this != null ? TextWrapper(this!, style: style) : null; +}