From 576a01512b39bf3c52d48751c571c46abab2cd9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 7 Feb 2023 09:44:34 +0100 Subject: [PATCH] refactor(ui_components): update example (close #115) --- .../lib/components/custom_app_bar.dart | 13 +++---- .../lib/components/custom_app_bar.g.dart | 36 ++++++++++++++++++ .../lib/components/custom_bottom_bar.dart | 17 +++------ .../lib/components/custom_bottom_bar.g.dart | 37 +++++++++++++++++++ .../lib/components/custom_error_widget.dart | 11 +++--- .../lib/components/custom_error_widget.g.dart | 30 +++++++++++++++ .../lib/components/custom_loading_widget.dart | 12 +++--- .../components/custom_loading_widget.g.dart | 31 ++++++++++++++++ .../wyatt_ui_components/example/lib/main.dart | 8 ++-- .../wyatt_ui_components/example/pubspec.yaml | 21 +++++++---- .../example/test/widget_test.dart | 2 +- 11 files changed, 175 insertions(+), 43 deletions(-) create mode 100644 packages/wyatt_ui_components/example/lib/components/custom_app_bar.g.dart create mode 100644 packages/wyatt_ui_components/example/lib/components/custom_bottom_bar.g.dart create mode 100644 packages/wyatt_ui_components/example/lib/components/custom_error_widget.g.dart create mode 100644 packages/wyatt_ui_components/example/lib/components/custom_loading_widget.g.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 80b9b396..924281cb 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 @@ -1,18 +1,15 @@ import 'package:flutter/material.dart'; +import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; -class CustomAppBar extends AppBarComponent { +part 'custom_app_bar.g.dart'; + +@ComponentCopyWithExtension() +class CustomAppBar extends AppBarComponent with $CustomAppBarCWMixin { const CustomAppBar({super.title, super.key}); @override Widget build(BuildContext context) => AppBar( title: Text(super.title ?? ''), ); - - @override - AppBarComponent? configure( - {String? title, Widget? leading, List? actions}) => - CustomAppBar( - title: title ?? this.title, - ); } 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 new file mode 100644 index 00000000..89c78122 --- /dev/null +++ b/packages/wyatt_ui_components/example/lib/components/custom_app_bar.g.dart @@ -0,0 +1,36 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'custom_app_bar.dart'; + +// ************************************************************************** +// ComponentCopyWithGenerator +// ************************************************************************** + +class $CustomAppBarCWProxyImpl implements $AppBarComponentCWProxy { + const $CustomAppBarCWProxyImpl(this._value); + final CustomAppBar _value; + @override + CustomAppBar title(String? title) => this(title: title); + @override + CustomAppBar leading(Widget? leading) => this(leading: leading); + @override + CustomAppBar actions(List? actions) => this(actions: actions); + @override + CustomAppBar key(Key? key) => this(key: key); + @override + CustomAppBar call({ + String? title, + Widget? leading, + List? actions, + Key? key, + }) => + CustomAppBar( + title: title ?? _value.title, + key: key ?? _value.key, + ); +} + +mixin $CustomAppBarCWMixin on Component { + $AppBarComponentCWProxy get copyWith => + $CustomAppBarCWProxyImpl(this as CustomAppBar); +} diff --git a/packages/wyatt_ui_components/example/lib/components/custom_bottom_bar.dart b/packages/wyatt_ui_components/example/lib/components/custom_bottom_bar.dart index 42eacfab..457f1e98 100644 --- a/packages/wyatt_ui_components/example/lib/components/custom_bottom_bar.dart +++ b/packages/wyatt_ui_components/example/lib/components/custom_bottom_bar.dart @@ -1,7 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; -class CustomBottomNavigationBar extends BottomNavigationBarComponent { +part 'custom_bottom_bar.g.dart'; + +@ComponentCopyWithExtension() +class CustomBottomNavigationBar extends BottomNavigationBarComponent + with $CustomBottomNavigationBarCWMixin { const CustomBottomNavigationBar({ super.currentIndex, super.onTap, @@ -27,14 +32,4 @@ class CustomBottomNavigationBar extends BottomNavigationBarComponent { ), ], ); - - @override - CustomBottomNavigationBar? configure({ - void Function(BuildContext, int)? onTap, - int currentIndex = 0, - }) => - CustomBottomNavigationBar( - onTap: onTap ?? this.onTap, - currentIndex: currentIndex, - ); } diff --git a/packages/wyatt_ui_components/example/lib/components/custom_bottom_bar.g.dart b/packages/wyatt_ui_components/example/lib/components/custom_bottom_bar.g.dart new file mode 100644 index 00000000..cc0e27b2 --- /dev/null +++ b/packages/wyatt_ui_components/example/lib/components/custom_bottom_bar.g.dart @@ -0,0 +1,37 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'custom_bottom_bar.dart'; + +// ************************************************************************** +// ComponentCopyWithGenerator +// ************************************************************************** + +class $CustomBottomNavigationBarCWProxyImpl + implements $BottomNavigationBarComponentCWProxy { + const $CustomBottomNavigationBarCWProxyImpl(this._value); + final CustomBottomNavigationBar _value; + @override + CustomBottomNavigationBar onTap(void Function(BuildContext, int)? onTap) => + this(onTap: onTap); + @override + CustomBottomNavigationBar currentIndex(int? currentIndex) => + this(currentIndex: currentIndex); + @override + CustomBottomNavigationBar key(Key? key) => this(key: key); + @override + CustomBottomNavigationBar call({ + void Function(BuildContext, int)? onTap, + int? currentIndex, + Key? key, + }) => + CustomBottomNavigationBar( + currentIndex: currentIndex ?? _value.currentIndex, + onTap: onTap ?? _value.onTap, + key: key ?? _value.key, + ); +} + +mixin $CustomBottomNavigationBarCWMixin on Component { + $BottomNavigationBarComponentCWProxy get copyWith => + $CustomBottomNavigationBarCWProxyImpl(this as CustomBottomNavigationBar); +} 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 736ae98a..450cf851 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 @@ -1,7 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; -class CustomErrorWidget extends ErrorWidgetComponent { +part 'custom_error_widget.g.dart'; + +@ComponentCopyWithExtension() +class CustomErrorWidget extends ErrorWidgetComponent + with $CustomErrorWidgetCWMixin { const CustomErrorWidget({super.error, super.key}); @override @@ -9,8 +14,4 @@ class CustomErrorWidget extends ErrorWidgetComponent { color: Colors.red, child: Center(child: Text(error ?? 'Error')), ); - - @override - ErrorWidgetComponent? configure({String? error}) => - CustomErrorWidget(error: error ?? this.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 new file mode 100644 index 00000000..67f26fcf --- /dev/null +++ b/packages/wyatt_ui_components/example/lib/components/custom_error_widget.g.dart @@ -0,0 +1,30 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'custom_error_widget.dart'; + +// ************************************************************************** +// ComponentCopyWithGenerator +// ************************************************************************** + +class $CustomErrorWidgetCWProxyImpl implements $ErrorWidgetComponentCWProxy { + const $CustomErrorWidgetCWProxyImpl(this._value); + final CustomErrorWidget _value; + @override + CustomErrorWidget error(String? error) => this(error: error); + @override + CustomErrorWidget key(Key? key) => this(key: key); + @override + CustomErrorWidget call({ + String? error, + Key? key, + }) => + CustomErrorWidget( + error: error ?? _value.error, + key: key ?? _value.key, + ); +} + +mixin $CustomErrorWidgetCWMixin on Component { + $ErrorWidgetComponentCWProxy get copyWith => + $CustomErrorWidgetCWProxyImpl(this as CustomErrorWidget); +} diff --git a/packages/wyatt_ui_components/example/lib/components/custom_loading_widget.dart b/packages/wyatt_ui_components/example/lib/components/custom_loading_widget.dart index 6d28e690..68ab4f0a 100644 --- a/packages/wyatt_ui_components/example/lib/components/custom_loading_widget.dart +++ b/packages/wyatt_ui_components/example/lib/components/custom_loading_widget.dart @@ -1,7 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; -class CustomLoadingWidget extends LoadingWidgetComponent { +part 'custom_loading_widget.g.dart'; + +@ComponentCopyWithExtension() +class CustomLoadingWidget extends LoadingWidgetComponent + with $CustomLoadingWidgetCWMixin { const CustomLoadingWidget({super.color, super.key}); @override @@ -10,9 +15,4 @@ class CustomLoadingWidget extends LoadingWidgetComponent { color: color, ), ); - - @override - CustomLoadingWidget? configure({Color? color}) => CustomLoadingWidget( - color: color ?? this.color, - ); } diff --git a/packages/wyatt_ui_components/example/lib/components/custom_loading_widget.g.dart b/packages/wyatt_ui_components/example/lib/components/custom_loading_widget.g.dart new file mode 100644 index 00000000..a6e78666 --- /dev/null +++ b/packages/wyatt_ui_components/example/lib/components/custom_loading_widget.g.dart @@ -0,0 +1,31 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'custom_loading_widget.dart'; + +// ************************************************************************** +// ComponentCopyWithGenerator +// ************************************************************************** + +class $CustomLoadingWidgetCWProxyImpl + implements $LoadingWidgetComponentCWProxy { + const $CustomLoadingWidgetCWProxyImpl(this._value); + final CustomLoadingWidget _value; + @override + CustomLoadingWidget color(Color? color) => this(color: color); + @override + CustomLoadingWidget key(Key? key) => this(key: key); + @override + CustomLoadingWidget call({ + Color? color, + Key? key, + }) => + CustomLoadingWidget( + color: color ?? _value.color, + key: key ?? _value.key, + ); +} + +mixin $CustomLoadingWidgetCWMixin on Component { + $LoadingWidgetComponentCWProxy get copyWith => + $CustomLoadingWidgetCWProxyImpl(this as CustomLoadingWidget); +} diff --git a/packages/wyatt_ui_components/example/lib/main.dart b/packages/wyatt_ui_components/example/lib/main.dart index 1587122a..7cb59bf7 100644 --- a/packages/wyatt_ui_components/example/lib/main.dart +++ b/packages/wyatt_ui_components/example/lib/main.dart @@ -1,4 +1,4 @@ -// Copyright (C) 2022 WYATT GROUP +// Copyright (C) 2023 WYATT GROUP // Please see the AUTHORS file for details. // // This program is free software: you can redistribute it and/or modify @@ -50,14 +50,14 @@ class Home extends StatelessWidget { Widget build(BuildContext context) => Scaffold( appBar: PreferredSize( preferredSize: const Size.fromHeight(60), - child: context.components.appBar?.configure(title: 'Example title') ?? + child: context.components.appBar?.copyWith.title('Example title') ?? const SizedBox.shrink(), ), body: Column( children: [ Expanded( child: context.components.errorWidget - ?.configure(error: 'Example erreur') ?? + ?.copyWith(error: 'Example erreur') ?? const SizedBox.shrink(), ), const SizedBox( @@ -65,7 +65,7 @@ class Home extends StatelessWidget { ), Expanded( child: context.components.loadingWidget - ?.configure(color: Colors.green) ?? + ?.copyWith(color: Colors.green) ?? const SizedBox.shrink(), ), ], diff --git a/packages/wyatt_ui_components/example/pubspec.yaml b/packages/wyatt_ui_components/example/pubspec.yaml index aea97e33..8a770109 100644 --- a/packages/wyatt_ui_components/example/pubspec.yaml +++ b/packages/wyatt_ui_components/example/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter project. # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -27,19 +27,26 @@ environment: # the latest version available on pub.dev. To see which dependencies have newer # versions available, run `flutter pub outdated`. dependencies: - flutter: sdk: flutter - - + wyatt_ui_components: path: "../" + wyatt_component_copy_with_extension: + git: + url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git + path: packages/wyatt_component_copy_with_extension + dev_dependencies: - flutter_test: sdk: flutter - + + build_runner: ^2.3.3 + wyatt_component_copy_with_gen: + git: + url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git + path: packages/wyatt_component_copy_with_gen wyatt_analysis: git: @@ -50,10 +57,8 @@ dev_dependencies: # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec - # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. diff --git a/packages/wyatt_ui_components/example/test/widget_test.dart b/packages/wyatt_ui_components/example/test/widget_test.dart index 52de7a27..bc890a0c 100644 --- a/packages/wyatt_ui_components/example/test/widget_test.dart +++ b/packages/wyatt_ui_components/example/test/widget_test.dart @@ -1,4 +1,4 @@ -// Copyright (C) 2022 WYATT GROUP +// Copyright (C) 2023 WYATT GROUP // Please see the AUTHORS file for details. // // This program is free software: you can redistribute it and/or modify