From 413589462bceca98334e5b222cc707b92f1f3d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 7 Feb 2023 10:49:09 +0100 Subject: [PATCH 1/2] refactor(ui_layout): migrate layouts using copywith component method (#116) --- .../lib/src/presentation/layouts/app_bar_layout.dart | 2 +- .../layouts/bottom_navigation_bar_layout.dart | 2 +- .../lib/src/presentation/layouts/frame_layout.dart | 4 ++-- packages/wyatt_ui_layout/pubspec.yaml | 11 +++-------- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/wyatt_ui_layout/lib/src/presentation/layouts/app_bar_layout.dart b/packages/wyatt_ui_layout/lib/src/presentation/layouts/app_bar_layout.dart index d591dfee..c7aae7db 100644 --- a/packages/wyatt_ui_layout/lib/src/presentation/layouts/app_bar_layout.dart +++ b/packages/wyatt_ui_layout/lib/src/presentation/layouts/app_bar_layout.dart @@ -35,7 +35,7 @@ class AppBarLayout extends Layout { Widget build(BuildContext context) => Scaffold( appBar: PreferredSize( preferredSize: const Size.fromHeight(60), - child: context.components.appBar?.configure( + child: context.components.appBar?.copyWith( title: title, leading: leading, actions: actions, diff --git a/packages/wyatt_ui_layout/lib/src/presentation/layouts/bottom_navigation_bar_layout.dart b/packages/wyatt_ui_layout/lib/src/presentation/layouts/bottom_navigation_bar_layout.dart index 632d5474..97287f0f 100644 --- a/packages/wyatt_ui_layout/lib/src/presentation/layouts/bottom_navigation_bar_layout.dart +++ b/packages/wyatt_ui_layout/lib/src/presentation/layouts/bottom_navigation_bar_layout.dart @@ -13,7 +13,7 @@ class BottomNavigationBarLayout extends Layout { @override Widget build(BuildContext context) => Scaffold( body: body, - bottomNavigationBar: context.components.bottomNavigationBar?.configure( + bottomNavigationBar: context.components.bottomNavigationBar?.copyWith( currentIndex: currentIndex ?? 0, ), ); diff --git a/packages/wyatt_ui_layout/lib/src/presentation/layouts/frame_layout.dart b/packages/wyatt_ui_layout/lib/src/presentation/layouts/frame_layout.dart index 4d8eb59c..e4347fa0 100644 --- a/packages/wyatt_ui_layout/lib/src/presentation/layouts/frame_layout.dart +++ b/packages/wyatt_ui_layout/lib/src/presentation/layouts/frame_layout.dart @@ -37,7 +37,7 @@ class FrameLayout extends Layout { Widget build(BuildContext context) => Scaffold( appBar: PreferredSize( preferredSize: const Size.fromHeight(60), - child: context.components.appBar?.configure( + child: context.components.appBar?.copyWith( title: title, leading: leading, actions: actions, @@ -45,7 +45,7 @@ class FrameLayout extends Layout { const SizedBox.shrink(), ), body: body, - bottomNavigationBar: context.components.bottomNavigationBar?.configure( + bottomNavigationBar: context.components.bottomNavigationBar?.copyWith( currentIndex: currentIndex ?? 0, ), ); diff --git a/packages/wyatt_ui_layout/pubspec.yaml b/packages/wyatt_ui_layout/pubspec.yaml index bfdcc394..d142bc60 100644 --- a/packages/wyatt_ui_layout/pubspec.yaml +++ b/packages/wyatt_ui_layout/pubspec.yaml @@ -4,28 +4,23 @@ repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/mas version: 0.0.1 environment: - sdk: '>=2.17.0 <3.0.0' + sdk: ">=2.17.0 <3.0.0" dependencies: - flutter: sdk: flutter - + wyatt_ui_components: git: url: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages path: packages/wyatt_ui_components dev_dependencies: - flutter_test: sdk: flutter - - - wyatt_analysis: git: url: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages ref: wyatt_analysis-v2.3.0 - path: packages/wyatt_analysis \ No newline at end of file + path: packages/wyatt_analysis -- 2.47.2 From ee8f08cc32435684dc51de0cd4ed7c89ebf4b958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Tue, 7 Feb 2023 10:49:56 +0100 Subject: [PATCH 2/2] refactor(ui_layout): update exemple (close #116) --- .../lib/components/custom_app_bar.dart | 16 +++----- .../lib/components/custom_app_bar.g.dart | 36 ++++++++++++++++++ .../custom_bottom_navigation_bar.dart | 17 +++------ .../custom_bottom_navigation_bar.g.dart | 37 +++++++++++++++++++ packages/wyatt_ui_layout/example/pubspec.yaml | 24 +++++++----- 5 files changed, 99 insertions(+), 31 deletions(-) create mode 100644 packages/wyatt_ui_layout/example/lib/components/custom_app_bar.g.dart create mode 100644 packages/wyatt_ui_layout/example/lib/components/custom_bottom_navigation_bar.g.dart diff --git a/packages/wyatt_ui_layout/example/lib/components/custom_app_bar.dart b/packages/wyatt_ui_layout/example/lib/components/custom_app_bar.dart index d31297fa..dd5394ca 100644 --- a/packages/wyatt_ui_layout/example/lib/components/custom_app_bar.dart +++ b/packages/wyatt_ui_layout/example/lib/components/custom_app_bar.dart @@ -1,7 +1,11 @@ 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, @@ -11,14 +15,4 @@ class CustomAppBar extends AppBarComponent { Widget build(BuildContext context) => AppBar( title: Text(title ?? ''), ); - - @override - AppBarComponent? configure({ - String? title, - Widget? leading, - List? actions, - }) => - CustomAppBar( - title: title ?? this.title, - ); } diff --git a/packages/wyatt_ui_layout/example/lib/components/custom_app_bar.g.dart b/packages/wyatt_ui_layout/example/lib/components/custom_app_bar.g.dart new file mode 100644 index 00000000..89c78122 --- /dev/null +++ b/packages/wyatt_ui_layout/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_layout/example/lib/components/custom_bottom_navigation_bar.dart b/packages/wyatt_ui_layout/example/lib/components/custom_bottom_navigation_bar.dart index 42eacfab..9ead57f2 100644 --- a/packages/wyatt_ui_layout/example/lib/components/custom_bottom_navigation_bar.dart +++ b/packages/wyatt_ui_layout/example/lib/components/custom_bottom_navigation_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_navigation_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_layout/example/lib/components/custom_bottom_navigation_bar.g.dart b/packages/wyatt_ui_layout/example/lib/components/custom_bottom_navigation_bar.g.dart new file mode 100644 index 00000000..fc15f676 --- /dev/null +++ b/packages/wyatt_ui_layout/example/lib/components/custom_bottom_navigation_bar.g.dart @@ -0,0 +1,37 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'custom_bottom_navigation_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_layout/example/pubspec.yaml b/packages/wyatt_ui_layout/example/pubspec.yaml index 3ce494bd..10795888 100644 --- a/packages/wyatt_ui_layout/example/pubspec.yaml +++ b/packages/wyatt_ui_layout/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,24 +27,32 @@ environment: # the latest version available on pub.dev. To see which dependencies have newer # versions available, run `flutter pub outdated`. dependencies: - flutter: - sdk: flutter - + sdk: flutter + wyatt_ui_layout: path: "../" wyatt_ui_components: - git: + git: url: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages path: packages/wyatt_ui_components + wyatt_component_copy_with_extension: + git: + url: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages + path: packages/wyatt_component_copy_with_extension + go_router: ^5.0.1 dev_dependencies: - flutter_test: sdk: flutter - + + build_runner: ^2.3.3 + wyatt_component_copy_with_gen: + git: + url: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages + path: packages/wyatt_component_copy_with_gen wyatt_analysis: git: @@ -55,10 +63,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. -- 2.47.2