Compare commits
3 Commits
04a87fe32a
...
46c51525e8
Author | SHA1 | Date | |
---|---|---|---|
![]() |
46c51525e8 | ||
![]() |
b025247002 | ||
![]() |
c70d4c6650 |
@ -1 +1 @@
|
||||
{"bricks":{"wyatt_clean_code":{"git":{"url":"ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git","path":"bricks/wyatt_clean_code","ref":"033baa65408ec6b68e6a2ef43e64c24708ef16a1"}},"wyatt_feature_brick":{"git":{"url":"ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git","path":"bricks/wyatt_feature_brick","ref":"033baa65408ec6b68e6a2ef43e64c24708ef16a1"}},"wyatt_package":{"git":{"url":"ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git","path":"bricks/wyatt_package","ref":"033baa65408ec6b68e6a2ef43e64c24708ef16a1"}}}}
|
||||
{"bricks":{"wyatt_clean_code":{"git":{"url":"ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git","path":"bricks/wyatt_clean_code","ref":"5009f1ef21d8531b773298c0fc08704d8f69afd1"}},"wyatt_feature_brick":{"git":{"url":"ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git","path":"bricks/wyatt_feature_brick","ref":"5009f1ef21d8531b773298c0fc08704d8f69afd1"}},"wyatt_package_template":{"git":{"url":"ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git","path":"bricks/wyatt_package_template","ref":"5009f1ef21d8531b773298c0fc08704d8f69afd1"}}}}
|
10
mason.yaml
10
mason.yaml
@ -1,13 +1,13 @@
|
||||
bricks:
|
||||
wyatt_clean_code:
|
||||
git:
|
||||
url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git
|
||||
url: "ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git"
|
||||
path: bricks/wyatt_clean_code
|
||||
wyatt_feature_brick:
|
||||
git:
|
||||
url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git
|
||||
url: "ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git"
|
||||
path: bricks/wyatt_feature_brick
|
||||
wyatt_package:
|
||||
wyatt_package_template:
|
||||
git:
|
||||
url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git
|
||||
path: bricks/wyatt_package
|
||||
url: "ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-bricks.git"
|
||||
path: bricks/wyatt_package_template
|
7
packages/wyatt_component_copy_with_extension/.gitignore
vendored
Normal file
7
packages/wyatt_component_copy_with_extension/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# https://dart.dev/guides/libraries/private-files
|
||||
# Created by `dart pub`
|
||||
.dart_tool/
|
||||
|
||||
# Avoid committing pubspec.lock for library packages; see
|
||||
# https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
pubspec.lock
|
24
packages/wyatt_component_copy_with_extension/.vscode/extensions.json
vendored
Normal file
24
packages/wyatt_component_copy_with_extension/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
{
|
||||
"recommendations": [
|
||||
"psioniq.psi-header",
|
||||
"blaugold.melos-code"
|
||||
]
|
||||
}
|
34
packages/wyatt_component_copy_with_extension/.vscode/launch.json
vendored
Normal file
34
packages/wyatt_component_copy_with_extension/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Example",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"cwd": "example/",
|
||||
"program": "lib/main.dart",
|
||||
"flutterMode": "debug"
|
||||
},
|
||||
]
|
||||
}
|
72
packages/wyatt_component_copy_with_extension/.vscode/settings.json
vendored
Normal file
72
packages/wyatt_component_copy_with_extension/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"dart.runPubGetOnPubspecChanges": "never",
|
||||
"bloc.newCubitTemplate.type": "equatable",
|
||||
"psi-header.changes-tracking": {
|
||||
"isActive": true
|
||||
},
|
||||
"psi-header.config": {
|
||||
"blankLinesAfter": 1,
|
||||
"forceToTop": true
|
||||
},
|
||||
"psi-header.lang-config": [
|
||||
{
|
||||
"beforeHeader": [
|
||||
"# -*- coding:utf-8 -*-",
|
||||
"#!/usr/bin/env python3"
|
||||
],
|
||||
"begin": "###",
|
||||
"end": "###",
|
||||
"language": "python",
|
||||
"prefix": "# "
|
||||
},
|
||||
{
|
||||
"beforeHeader": [
|
||||
"#!/usr/bin/env sh",
|
||||
""
|
||||
],
|
||||
"language": "shellscript",
|
||||
"begin": "",
|
||||
"end": "",
|
||||
"prefix": "# "
|
||||
},
|
||||
{
|
||||
"begin": "",
|
||||
"end": "",
|
||||
"language": "dart",
|
||||
"prefix": "// "
|
||||
},
|
||||
{
|
||||
"begin": "",
|
||||
"end": "",
|
||||
"language": "yaml",
|
||||
"prefix": "# "
|
||||
},
|
||||
{
|
||||
"begin": "<!--",
|
||||
"end": "-->",
|
||||
"language": "markdown",
|
||||
},
|
||||
],
|
||||
"psi-header.templates": [
|
||||
{
|
||||
"language": "*",
|
||||
"template": [
|
||||
"Copyright (C) <<year>> 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 <https://www.gnu.org/licenses/>."
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
## 1.0.0
|
||||
|
||||
- Initial version.
|
66
packages/wyatt_component_copy_with_extension/README.md
Normal file
66
packages/wyatt_component_copy_with_extension/README.md
Normal file
@ -0,0 +1,66 @@
|
||||
<!--
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
# Flutter - Component Copy With Extension
|
||||
|
||||
<p align="left">
|
||||
<a href="https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis"><img src="https://img.shields.io/badge/Style-Wyatt%20Analysis-blue.svg?style=flat-square" alt="Style: Wyatt Analysis" /></a>
|
||||
<img src="https://img.shields.io/badge/SDK-Flutter-blue?style=flat-square" alt="SDK: Flutter" />
|
||||
</p>
|
||||
|
||||
This package provides annotations for generating code and simplifying the use of an UI kit within a Flutter application. **The package contains only the annotation classes**.
|
||||
|
||||
## Annotation Classes
|
||||
|
||||
#### `ComponentProxyExtension`
|
||||
|
||||
This annotation class is used to annotate a new component of an UI kit in the `wyatt_ui_components` package. It generates the abstract proxy of the component and allows access to all its properties in different packages and throughout the application.
|
||||
|
||||
```dart
|
||||
part 'text_field_component.g.dart';
|
||||
|
||||
@ComponentProxyExtension()
|
||||
abstract class TextFieldComponent extends Component {
|
||||
with CopyWithMixin<$TextFieldComponentCWProxy> {
|
||||
|
||||
const TextFieldComponent({
|
||||
...
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
#### `ComponentCopyWithExtension`
|
||||
|
||||
This annotation class is used to annotate the implementation of components directly in the application. It generates the implementation of the proxy and the mixin to ensure that the component meets the specifications defined in the `wyatt_ui_components package`.
|
||||
|
||||
```dart
|
||||
part 'text_field_component.g.dart';
|
||||
|
||||
@ComponentProxyExtension()
|
||||
abstract class TextFieldComponent extends Component {
|
||||
with CopyWithMixin<$TextFieldComponentCWProxy> {
|
||||
|
||||
const TextFieldComponent({
|
||||
...
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Additional features
|
||||
|
||||
The skipFields field allows you to directly and specifically change a field. This makes it easier to use. You can disable it through annotation.
|
@ -0,0 +1,7 @@
|
||||
|
||||
include: package:wyatt_analysis/analysis_options.flutter.yaml
|
||||
|
||||
|
||||
|
||||
|
||||
|
44
packages/wyatt_component_copy_with_extension/example/.gitignore
vendored
Normal file
44
packages/wyatt_component_copy_with_extension/example/.gitignore
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
migrate_working_dir/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
**/doc/api/
|
||||
**/ios/Flutter/.last_build_id
|
||||
.dart_tool/
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
.packages
|
||||
.pub-cache/
|
||||
.pub/
|
||||
/build/
|
||||
|
||||
# Symbolication related
|
||||
app.*.symbols
|
||||
|
||||
# Obfuscation related
|
||||
app.*.map.json
|
||||
|
||||
# Android Studio will place build artifacts here
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
@ -0,0 +1,30 @@
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled.
|
||||
|
||||
version:
|
||||
revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
channel: stable
|
||||
|
||||
project_type: app
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
- platform: web
|
||||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
@ -0,0 +1,16 @@
|
||||
# example
|
||||
|
||||
A new Flutter project.
|
||||
|
||||
## Getting Started
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
@ -0,0 +1,7 @@
|
||||
|
||||
include: package:wyatt_analysis/analysis_options.flutter.yaml
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
|
||||
|
||||
@ComponentProxyExtension()
|
||||
class BasicComponentAnnotationExemple {}
|
||||
|
||||
@ComponentProxyExtension(skipFields: true)
|
||||
class ComponentAnnotationExempleWithSkipFields {}
|
||||
|
||||
@ComponentCopyWithExtension()
|
||||
class BasicCustomComponent {}
|
||||
|
||||
@ComponentCopyWithExtension(skipFields: false)
|
||||
class CustomComponentAnnotationExempleWithSkipFields {}
|
@ -0,0 +1,27 @@
|
||||
name: component_copy_with_extension_example
|
||||
description: A new Flutter project.
|
||||
version: 1.0.0
|
||||
|
||||
publish_to: "none"
|
||||
|
||||
environment:
|
||||
sdk: ">=2.19.0 <3.0.0"
|
||||
flutter: ">=3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
wyatt_component_copy_with_extension:
|
||||
path: "../"
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
wyatt_analysis:
|
||||
hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
|
||||
version: ^2.3.0
|
||||
|
||||
# The following section is specific to Flutter.
|
||||
flutter:
|
||||
uses-material-design: true
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
/// Extension for component copy with feature
|
||||
library component_copy_with_extension;
|
||||
|
||||
export './src/domain/domain.dart';
|
||||
export 'src/component_copy_with_extension.dart';
|
||||
export 'src/component_proxy_extension.dart';
|
@ -0,0 +1,25 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:meta/meta_meta.dart';
|
||||
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
|
||||
|
||||
/// Annotation used to indicate that the `copyWith` extension
|
||||
/// should be generated for the compononent.
|
||||
@Target({TargetKind.classType})
|
||||
class ComponentCopyWithExtension extends ComponentAnnotation {
|
||||
const ComponentCopyWithExtension({super.skipFields});
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:meta/meta_meta.dart';
|
||||
|
||||
@Target({TargetKind.classType})
|
||||
class ComponentProxyExtension {
|
||||
const ComponentProxyExtension({
|
||||
this.skipFields = true,
|
||||
});
|
||||
|
||||
final bool? skipFields;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
abstract class ComponentAnnotation {
|
||||
const ComponentAnnotation({this.skipFields = true});
|
||||
|
||||
/// Prevent the library from generating `copyWith` functions for individual
|
||||
/// fields e.g. `instance.copyWith.id("123")`. If you want to use only
|
||||
/// copyWith(...) function. Default is `true`.
|
||||
final bool? skipFields;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
export './component_annotation.dart';
|
20
packages/wyatt_component_copy_with_extension/pubspec.yaml
Normal file
20
packages/wyatt_component_copy_with_extension/pubspec.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
name: wyatt_component_copy_with_extension
|
||||
description: Extension for component copy with feature.
|
||||
repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/component_copy_with_extension
|
||||
version: 1.0.0
|
||||
|
||||
environment:
|
||||
sdk: ">=2.19.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
meta: ^1.8.0
|
||||
path: ^1.8.0
|
||||
|
||||
dev_dependencies:
|
||||
wyatt_analysis:
|
||||
hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
|
||||
version: ^2.3.0
|
||||
|
||||
# The following section is specific to Flutter.
|
||||
flutter:
|
||||
uses-material-design: true
|
7
packages/wyatt_component_copy_with_gen/.gitignore
vendored
Normal file
7
packages/wyatt_component_copy_with_gen/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# https://dart.dev/guides/libraries/private-files
|
||||
# Created by `dart pub`
|
||||
.dart_tool/
|
||||
|
||||
# Avoid committing pubspec.lock for library packages; see
|
||||
# https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
pubspec.lock
|
24
packages/wyatt_component_copy_with_gen/.vscode/extensions.json
vendored
Normal file
24
packages/wyatt_component_copy_with_gen/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
{
|
||||
"recommendations": [
|
||||
"psioniq.psi-header",
|
||||
"blaugold.melos-code"
|
||||
]
|
||||
}
|
34
packages/wyatt_component_copy_with_gen/.vscode/launch.json
vendored
Normal file
34
packages/wyatt_component_copy_with_gen/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Example",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"cwd": "example/",
|
||||
"program": "lib/main.dart",
|
||||
"flutterMode": "debug"
|
||||
},
|
||||
]
|
||||
}
|
72
packages/wyatt_component_copy_with_gen/.vscode/settings.json
vendored
Normal file
72
packages/wyatt_component_copy_with_gen/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"dart.runPubGetOnPubspecChanges": "never",
|
||||
"bloc.newCubitTemplate.type": "equatable",
|
||||
"psi-header.changes-tracking": {
|
||||
"isActive": true
|
||||
},
|
||||
"psi-header.config": {
|
||||
"blankLinesAfter": 1,
|
||||
"forceToTop": true
|
||||
},
|
||||
"psi-header.lang-config": [
|
||||
{
|
||||
"beforeHeader": [
|
||||
"# -*- coding:utf-8 -*-",
|
||||
"#!/usr/bin/env python3"
|
||||
],
|
||||
"begin": "###",
|
||||
"end": "###",
|
||||
"language": "python",
|
||||
"prefix": "# "
|
||||
},
|
||||
{
|
||||
"beforeHeader": [
|
||||
"#!/usr/bin/env sh",
|
||||
""
|
||||
],
|
||||
"language": "shellscript",
|
||||
"begin": "",
|
||||
"end": "",
|
||||
"prefix": "# "
|
||||
},
|
||||
{
|
||||
"begin": "",
|
||||
"end": "",
|
||||
"language": "dart",
|
||||
"prefix": "// "
|
||||
},
|
||||
{
|
||||
"begin": "",
|
||||
"end": "",
|
||||
"language": "yaml",
|
||||
"prefix": "# "
|
||||
},
|
||||
{
|
||||
"begin": "<!--",
|
||||
"end": "-->",
|
||||
"language": "markdown",
|
||||
},
|
||||
],
|
||||
"psi-header.templates": [
|
||||
{
|
||||
"language": "*",
|
||||
"template": [
|
||||
"Copyright (C) <<year>> 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 <https://www.gnu.org/licenses/>."
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
3
packages/wyatt_component_copy_with_gen/CHANGELOG.md
Normal file
3
packages/wyatt_component_copy_with_gen/CHANGELOG.md
Normal file
@ -0,0 +1,3 @@
|
||||
## 1.0.0
|
||||
|
||||
- Initial version.
|
57
packages/wyatt_component_copy_with_gen/README.md
Normal file
57
packages/wyatt_component_copy_with_gen/README.md
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
# Dart - Component Copy With Gen
|
||||
|
||||
<p align="left">
|
||||
<a href="https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis"><img src="https://img.shields.io/badge/Style-Wyatt%20Analysis-blue.svg?style=flat-square" alt="Style: Wyatt Analysis" /></a>
|
||||
<img src="https://img.shields.io/badge/SDK-Dart%20%7C%20Flutter-blue?style=flat-square" alt="SDK: Dart & Flutter" />
|
||||
</p>
|
||||
|
||||
A Dart package for generating code from annotations to ease the use of a UIKit in Flutter applications. The generated code is based on the annotation classes present in the 'wyatt_component_copy_with_extension' package.
|
||||
|
||||
## Features
|
||||
|
||||
- Supports the generation of abstract proxies in the `wyatt_ui_components` package.
|
||||
- Supports direct use in Flutter applications.
|
||||
|
||||
## Usage
|
||||
|
||||
### In the 'wyatt_ui_components' package
|
||||
|
||||
- Add the appropriate annotation when addicdng a new component.
|
||||
- Run the build runner command to generate the proxy.
|
||||
|
||||
### In Flutter applications
|
||||
|
||||
- Add the following dependencies to your pubspec.yaml:
|
||||
|
||||
```yaml
|
||||
dependencies:
|
||||
...
|
||||
wyatt_component_copy_with_extension: ^0.0.1
|
||||
dev_dependencies:
|
||||
...
|
||||
wyatt_component_copy_with_gen: ^0.0.1
|
||||
build_runner: ^2.3.3
|
||||
```
|
||||
|
||||
- In your UIKit, extend the desired component class and add the appropriate annotation.
|
||||
- Run the code generation command via the build runner.
|
||||
|
||||
For further details and additional features on class annotation, see the 'wyatt_component_copy_with_extension' package's README.
|
@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
|
||||
include: package:wyatt_analysis/analysis_options.yaml
|
||||
|
||||
|
||||
|
21
packages/wyatt_component_copy_with_gen/build.yaml
Normal file
21
packages/wyatt_component_copy_with_gen/build.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
targets:
|
||||
$default:
|
||||
builders:
|
||||
component_copy_with_gen:
|
||||
enabled: true
|
||||
generate_for:
|
||||
exclude:
|
||||
- test
|
||||
- example
|
||||
include:
|
||||
- test/gen_*
|
||||
|
||||
builders:
|
||||
component_copy_with_gen:
|
||||
target: ":component_copy_with_gen"
|
||||
import: "package:wyatt_component_copy_with_gen/component_copy_with_gen.dart"
|
||||
builder_factories: ["componentCopyWithReporter"]
|
||||
build_extensions: { ".dart": ["copy_with_extension_gen.g.part"] }
|
||||
auto_apply: dependents
|
||||
build_to: cache
|
||||
applies_builders: ["source_gen|combining_builder"]
|
44
packages/wyatt_component_copy_with_gen/example/.gitignore
vendored
Normal file
44
packages/wyatt_component_copy_with_gen/example/.gitignore
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
migrate_working_dir/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
**/doc/api/
|
||||
**/ios/Flutter/.last_build_id
|
||||
.dart_tool/
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
.packages
|
||||
.pub-cache/
|
||||
.pub/
|
||||
/build/
|
||||
|
||||
# Symbolication related
|
||||
app.*.symbols
|
||||
|
||||
# Obfuscation related
|
||||
app.*.map.json
|
||||
|
||||
# Android Studio will place build artifacts here
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
30
packages/wyatt_component_copy_with_gen/example/.metadata
Normal file
30
packages/wyatt_component_copy_with_gen/example/.metadata
Normal file
@ -0,0 +1,30 @@
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled.
|
||||
|
||||
version:
|
||||
revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
channel: stable
|
||||
|
||||
project_type: app
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
- platform: web
|
||||
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
16
packages/wyatt_component_copy_with_gen/example/README.md
Normal file
16
packages/wyatt_component_copy_with_gen/example/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# example
|
||||
|
||||
A new Flutter project.
|
||||
|
||||
## Getting Started
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
|
||||
include: package:wyatt_analysis/analysis_options.yaml
|
||||
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
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';
|
||||
|
||||
// part 'custom_app_bar_example.g.dart';
|
||||
|
||||
@ComponentCopyWithExtension()
|
||||
class CustomAppBarExample extends AppBarComponent
|
||||
with $CustomAppBarExampleCWProxyImpl {
|
||||
const CustomAppBarExample({super.title, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AppBar(
|
||||
title: Text(super.title ?? ''),
|
||||
);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'custom_app_bar_example.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// ComponentCopyWithGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class $CustomAppBarExampleCWProxyImpl implements $AppBarComponentCWProxy {
|
||||
const $CustomAppBarExampleCWProxyImpl(this._value);
|
||||
final CustomAppBarExample _value;
|
||||
@override
|
||||
CustomAppBarExample title(String? title) => this(title: title);
|
||||
@override
|
||||
CustomAppBarExample leading(Widget? leading) => this(leading: leading);
|
||||
@override
|
||||
CustomAppBarExample actions(List<Widget>? actions) => this(actions: actions);
|
||||
@override
|
||||
CustomAppBarExample key(Key? key) => this(key: key);
|
||||
@override
|
||||
CustomAppBarExample call({
|
||||
String? title,
|
||||
Widget? leading,
|
||||
List<Widget>? actions,
|
||||
Key? key,
|
||||
}) =>
|
||||
CustomAppBarExample(
|
||||
title: title ?? _value.title,
|
||||
key: key ?? _value.key,
|
||||
);
|
||||
}
|
||||
|
||||
mixin $CustomAppBarExampleCWMixin on Component {
|
||||
$AppBarComponentCWProxy get copyWith =>
|
||||
$CustomAppBarExampleCWProxyImpl(this as CustomAppBarExample);
|
||||
}
|
28
packages/wyatt_component_copy_with_gen/example/pubspec.yaml
Normal file
28
packages/wyatt_component_copy_with_gen/example/pubspec.yaml
Normal file
@ -0,0 +1,28 @@
|
||||
name: component_copy_with_gen_example
|
||||
description: A new Flutter project.
|
||||
version: 1.0.0
|
||||
|
||||
publish_to: "none"
|
||||
|
||||
environment:
|
||||
sdk: ">=2.19.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
wyatt_component_copy_with_extension:
|
||||
path: "../../wyatt_component_copy_with_extension"
|
||||
|
||||
wyatt_ui_components:
|
||||
git:
|
||||
url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git
|
||||
path: packages/wyatt_ui_components
|
||||
|
||||
dev_dependencies:
|
||||
build_runner: ^2.3.3
|
||||
wyatt_component_copy_with_gen:
|
||||
path: "../"
|
||||
wyatt_analysis:
|
||||
hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
|
||||
version: ^2.3.0
|
@ -0,0 +1,21 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
/// Generator for copywith method for components
|
||||
library component_copy_with_gen;
|
||||
|
||||
export 'src/builder.dart';
|
||||
export 'src/generators/component_copy_with_generator.dart';
|
28
packages/wyatt_component_copy_with_gen/lib/src/builder.dart
Normal file
28
packages/wyatt_component_copy_with_gen/lib/src/builder.dart
Normal file
@ -0,0 +1,28 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:build/build.dart';
|
||||
import 'package:source_gen/source_gen.dart';
|
||||
import 'package:wyatt_component_copy_with_gen/src/generators/component_copy_with_generator.dart';
|
||||
import 'package:wyatt_component_copy_with_gen/src/generators/component_proxy_generator.dart';
|
||||
|
||||
Builder componentCopyWithReporter(BuilderOptions options) => SharedPartBuilder(
|
||||
[
|
||||
ComponentProxyGenerator(),
|
||||
ComponentCopyWithGenerator(),
|
||||
],
|
||||
'component_copy_with',
|
||||
);
|
@ -0,0 +1,97 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:build/build.dart';
|
||||
import 'package:source_gen/source_gen.dart';
|
||||
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
|
||||
|
||||
class ComponentCopyWithGenerator
|
||||
extends GeneratorForAnnotation<ComponentCopyWithExtension> {
|
||||
@override
|
||||
FutureOr<String> generateForAnnotatedElement(
|
||||
Element element,
|
||||
ConstantReader annotation,
|
||||
BuildStep buildStep,
|
||||
) {
|
||||
/// Check element type
|
||||
if (element is! ClassElement) {
|
||||
throw InvalidGenerationSourceError(
|
||||
'Only classes can be annotated with "CopyWith". "$element" is '
|
||||
'not a ClassElement.',
|
||||
element: element,
|
||||
);
|
||||
}
|
||||
|
||||
final classAnnotation = ComponentCopyWithExtension(
|
||||
skipFields: annotation.peek('skipFields')?.boolValue ?? true,
|
||||
);
|
||||
|
||||
final generatedCode = StringBuffer()
|
||||
|
||||
// Generate CopyWith Proxy implementation.
|
||||
..write('class \$${element.displayName}CWProxyImpl implements '
|
||||
'\$${element.supertype?.getDisplayString(
|
||||
withNullability: false,
|
||||
)}CWProxy { '
|
||||
'const \$${element.displayName}CWProxyImpl '
|
||||
'(this._value); '
|
||||
'final ${element.displayName} _value;');
|
||||
|
||||
if (classAnnotation.skipFields ?? true) {
|
||||
for (final superField
|
||||
in element.supertype!.element.constructors.first.parameters) {
|
||||
final superFieldDisplayName = superField.displayName;
|
||||
generatedCode.write('@override ${element.displayName} '
|
||||
'$superFieldDisplayName(${superField.type.getDisplayString(
|
||||
withNullability: false,
|
||||
)}? '
|
||||
' $superFieldDisplayName)'
|
||||
' => this($superFieldDisplayName : $superFieldDisplayName); ');
|
||||
}
|
||||
}
|
||||
|
||||
generatedCode.write('@override ${element.displayName} call ({');
|
||||
|
||||
for (final superField
|
||||
in element.supertype!.element.constructors.first.parameters) {
|
||||
final superFieldDisplayName = superField.displayName;
|
||||
generatedCode.write('${superField.type.getDisplayString(
|
||||
withNullability: false,
|
||||
)}? $superFieldDisplayName,');
|
||||
}
|
||||
|
||||
generatedCode.write('})=>${element.displayName}(');
|
||||
|
||||
for (final superField in element.constructors.first.parameters) {
|
||||
final superFieldDisplayName = superField.displayName;
|
||||
generatedCode.write('$superFieldDisplayName:$superFieldDisplayName?? '
|
||||
'_value.$superFieldDisplayName,');
|
||||
}
|
||||
|
||||
generatedCode
|
||||
..write(');}')
|
||||
..write(
|
||||
'mixin \$${element.displayName}CWMixin on Component { '
|
||||
'\$${element.supertype?.element.displayName}CWProxy get copyWith => '
|
||||
'\$${element.displayName}CWProxyImpl(this as ${element.displayName});}',
|
||||
);
|
||||
|
||||
return generatedCode.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/nullability_suffix.dart';
|
||||
import 'package:build/build.dart';
|
||||
import 'package:source_gen/source_gen.dart';
|
||||
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
|
||||
|
||||
class ComponentProxyGenerator
|
||||
extends GeneratorForAnnotation<ComponentProxyExtension> {
|
||||
@override
|
||||
FutureOr<String> generateForAnnotatedElement(
|
||||
Element element,
|
||||
ConstantReader annotation,
|
||||
BuildStep buildStep,
|
||||
) {
|
||||
/// Check element type
|
||||
if (element is! ClassElement) {
|
||||
throw InvalidGenerationSourceError(
|
||||
'Only classes can be annotated with "CopyWith". "$element" is '
|
||||
'not a ClassElement.',
|
||||
element: element,
|
||||
);
|
||||
}
|
||||
|
||||
final classAnnotation = ComponentProxyExtension(
|
||||
skipFields: annotation.peek('skipFields')?.boolValue ?? true,
|
||||
);
|
||||
|
||||
final generatedCode = StringBuffer()
|
||||
..write('abstract class \$${element.displayName}CWProxy {');
|
||||
|
||||
if (classAnnotation.skipFields ?? true) {
|
||||
for (final field in element.constructors.first.parameters) {
|
||||
generatedCode.write(
|
||||
'${element.displayName} '
|
||||
'${field.displayName}(${field.type.getDisplayString(
|
||||
withNullability: false,
|
||||
)}? '
|
||||
'${field.displayName});',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
generatedCode.write('${element.displayName} call({');
|
||||
|
||||
for (final field in element.constructors.first.parameters) {
|
||||
if (field.type.nullabilitySuffix == NullabilitySuffix.question) {
|
||||
generatedCode.write('${field.type.getDisplayString(
|
||||
withNullability: false,
|
||||
)}? ${field.displayName}, ');
|
||||
}
|
||||
}
|
||||
|
||||
generatedCode.write('});}');
|
||||
|
||||
return generatedCode.toString();
|
||||
}
|
||||
}
|
23
packages/wyatt_component_copy_with_gen/pubspec.yaml
Normal file
23
packages/wyatt_component_copy_with_gen/pubspec.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
name: wyatt_component_copy_with_gen
|
||||
description: Generator for copywith method for components.
|
||||
repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/component_copy_with_gen
|
||||
version: 1.0.0
|
||||
|
||||
environment:
|
||||
sdk: ">=2.19.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
path: ^1.8.0
|
||||
build: ^2.3.1
|
||||
source_gen: ^1.2.7
|
||||
analyzer: ^5.4.0
|
||||
|
||||
wyatt_component_copy_with_extension:
|
||||
path: ../wyatt_component_copy_with_extension
|
||||
|
||||
dev_dependencies:
|
||||
test: ^1.21.0
|
||||
|
||||
wyatt_analysis:
|
||||
hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
|
||||
version: ^2.3.0
|
Loading…
x
Reference in New Issue
Block a user