master #81

Closed
malo wants to merge 322 commits from master into feat/bloc_layout/new-package
20 changed files with 662 additions and 0 deletions
Showing only changes of commit 46c51525e8 - Show all commits

View 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

View 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"
]
}

View 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"
},
]
}

View 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/>."
],
}
],
}

View File

@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

View 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.

View File

@ -0,0 +1,7 @@
include: package:wyatt_analysis/analysis_options.yaml

View 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"]

View 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

View 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'

View 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.

View File

@ -0,0 +1,7 @@
include: package:wyatt_analysis/analysis_options.yaml

View File

@ -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 ?? ''),
);
}

View File

@ -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);
}

View 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

View File

@ -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';

View 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',
);

View File

@ -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();
}
}

View File

@ -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();
}
}

View 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