diff --git a/packages/wyatt_analysis/.latest_version b/packages/wyatt_analysis/.latest_version index 005119ba..35cee72d 100644 --- a/packages/wyatt_analysis/.latest_version +++ b/packages/wyatt_analysis/.latest_version @@ -1 +1 @@ -2.4.1 +2.4.3 diff --git a/packages/wyatt_analysis/README.md b/packages/wyatt_analysis/README.md index 95d85e02..d252e166 100644 --- a/packages/wyatt_analysis/README.md +++ b/packages/wyatt_analysis/README.md @@ -20,7 +20,7 @@ ![SDK: Dart & Flutter](https://img.shields.io/badge/SDK-Dart%20%7C%20Flutter-blue?style=flat-square) -This package provides lint rules for Dart and Flutter which are used at [Wyatt Studio](https://wyatt-studio.fr). For more information, see the complete list of options in **lib/analysis_options.2.4.1.yaml**. +This package provides lint rules for Dart and Flutter which are used at [Wyatt Studio](https://wyatt-studio.fr). For more information, see the complete list of options in **lib/analysis_options.2.4.3.yaml**. **Note**: This package was heavily inspired by [pedantic](https://github.com/dart-lang/pedantic), [Very Good Analysis](https://github.com/VeryGoodOpenSource/very_good_analysis) and the official [flutter_lints](https://pub.dev/packages/flutter_lints). @@ -29,7 +29,7 @@ This package provides lint rules for Dart and Flutter which are used at [Wyatt Using CLI: ```sh -dart pub add wyatt_analysis:2.4.1 --dev --hosted-url=https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ +dart pub add wyatt_analysis:2.4.3 --dev --hosted-url=https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ ``` ## Usage @@ -39,7 +39,7 @@ To use the lints, add a dependency in your `pubspec.yaml` : ```yaml wyatt_analysis: hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ - version: 2.4.1 + version: 2.4.3 ``` Then, add an include in `analysis_options.yaml` : @@ -57,13 +57,13 @@ include: package:wyatt_analysis/analysis_options.flutter.yaml If you wish to restrict the lint version, specify a version of `analysis_options.yaml` instead: ```yaml -include: package:wyatt_analysis/analysis_options.flutter.2.4.1.yaml +include: package:wyatt_analysis/analysis_options.flutter.2.4.3.yaml ``` If you just want **Dart** version: ```yaml -include: package:wyatt_analysis/analysis_options.2.4.1.yaml +include: package:wyatt_analysis/analysis_options.2.4.3.yaml ``` ## Suppressing Lints diff --git a/packages/wyatt_analysis/lib/analysis_options.2.4.2.yaml b/packages/wyatt_analysis/lib/analysis_options.2.4.2.yaml new file mode 100644 index 00000000..7e6df9b3 --- /dev/null +++ b/packages/wyatt_analysis/lib/analysis_options.2.4.2.yaml @@ -0,0 +1,217 @@ +# 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 . + +analyzer: + language: + strict-casts: true + strict-inference: true + strict-raw-types: true + + errors: + todo: ignore + close_sinks: ignore + missing_required_param: error + missing_return: error + + exclude: + - lib/l10n/** + - lib/generated/** + - lib/gen/** + - lib/generated_plugin_registrant.dart + - test/.test_coverage.dart + - "**/*.g.dart" + - "**/*.freezed.dart" + +linter: + rules: + - always_declare_return_types + - always_put_control_body_on_new_line + - always_put_required_named_parameters_first + - always_require_non_null_named_parameters + - always_use_package_imports + - annotate_overrides + - avoid_bool_literals_in_conditional_expressions + - avoid_catching_errors + - avoid_double_and_int_checks + - avoid_dynamic_calls + - avoid_empty_else + - avoid_equals_and_hash_code_on_mutable_classes + - avoid_escaping_inner_quotes + - avoid_field_initializers_in_const_classes + - avoid_final_parameters + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_js_rounded_ints + - avoid_multiple_declarations_per_line + - avoid_null_checks_in_equality_operators + - avoid_positional_boolean_parameters + - avoid_private_typedef_functions + - avoid_redundant_argument_values + - avoid_relative_lib_imports + - avoid_renaming_method_parameters + - avoid_return_types_on_setters + - avoid_returning_null + - avoid_returning_null_for_future + - avoid_returning_null_for_void + - avoid_returning_this + - avoid_setters_without_getters + - avoid_shadowing_type_parameters + - avoid_single_cascade_in_expression_statements + - avoid_slow_async_io + - avoid_type_to_string + - avoid_types_as_parameter_names + - avoid_types_on_closure_parameters + - avoid_unused_constructor_parameters + - avoid_void_async + - await_only_futures + - camel_case_extensions + - camel_case_types + - cancel_subscriptions + - cascade_invocations + - cast_nullable_to_non_nullable + - collection_methods_unrelated_type + - combinators_ordering + - comment_references + - conditional_uri_does_not_exist + - constant_identifier_names + - control_flow_in_finally + - curly_braces_in_flow_control_structures + - depend_on_referenced_packages + - deprecated_consistency + - directives_ordering + - empty_catches + - empty_constructor_bodies + - empty_statements + - eol_at_end_of_file + - exhaustive_cases + - file_names + - flutter_style_todos + - hash_and_equals + - implementation_imports + - implicit_call_tearoffs + - iterable_contains_unrelated_type + - join_return_with_assignment + - leading_newlines_in_multiline_strings + - library_names + - library_prefixes + - library_private_types_in_public_api + - lines_longer_than_80_chars + - list_remove_unrelated_type + - literal_only_boolean_expressions + - missing_whitespace_between_adjacent_strings + - no_adjacent_strings_in_list + - no_default_cases + - no_duplicate_case_values + - no_leading_underscores_for_library_prefixes + - no_leading_underscores_for_local_identifiers + - no_runtimeType_toString + - non_constant_identifier_names + - noop_primitive_operations + - null_check_on_nullable_type_parameter + - null_closures + - one_member_abstracts + - only_throw_errors + - overridden_fields + - package_api_docs + - package_names + - package_prefixed_library_names + - parameter_assignments + - prefer_adjacent_string_concatenation + - prefer_asserts_in_initializer_lists + - prefer_asserts_with_message + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_const_constructors + - prefer_const_constructors_in_immutables + - prefer_const_declarations + - prefer_const_literals_to_create_immutables + - prefer_constructors_over_static_methods + - prefer_contains + - prefer_equal_for_default_values + - prefer_expression_function_bodies + - prefer_final_fields + - prefer_final_in_for_each + - prefer_final_locals + - prefer_for_elements_to_map_fromIterable + - prefer_function_declarations_over_variables + - prefer_generic_function_type_aliases + - prefer_if_elements_to_conditional_expressions + - prefer_if_null_operators + - prefer_initializing_formals + - prefer_inlined_adds + - prefer_int_literals + - prefer_interpolation_to_compose_strings + - prefer_is_empty + - prefer_is_not_empty + - prefer_is_not_operator + - prefer_iterable_whereType + - prefer_mixin + - prefer_null_aware_method_calls + - prefer_null_aware_operators + - prefer_single_quotes + - prefer_spread_collections + - prefer_typing_uninitialized_variables + - prefer_void_to_null + - provide_deprecation_message + - recursive_getters + - require_trailing_commas + - slash_for_doc_comments + - sort_constructors_first + - sort_unnamed_constructors_first + - test_types_in_equals + - throw_in_finally + - tighten_type_of_initializing_formals + - type_annotate_public_apis + - type_init_formals + - unawaited_futures + - unnecessary_await_in_return + - unnecessary_brace_in_string_interps + - unnecessary_const + - unnecessary_constructor_name + - unnecessary_getters_setters + - unnecessary_lambdas + - unnecessary_late + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_null_checks + - unnecessary_null_in_if_null_operators + - unnecessary_nullable_for_final_variable_declarations + - unnecessary_overrides + - unnecessary_parenthesis + - unnecessary_raw_strings + - unnecessary_statements + - unnecessary_string_escapes + - unnecessary_string_interpolations + - unnecessary_this + - unnecessary_to_list_in_spreads + - unrelated_type_equality_checks + - unsafe_html + - use_enums + - use_function_type_syntax_for_parameters + - use_if_null_to_convert_nulls_to_bools + - use_is_even_rather_than_modulo + - use_late_for_private_fields_and_variables + - use_named_constants + - use_raw_strings + - use_rethrow_when_possible + - use_setters_to_change_properties + - use_string_buffers + - use_string_in_part_of_directives + - use_super_parameters + - use_test_throws_matchers + - use_to_and_as_if_applicable + - valid_regexps + - void_checks diff --git a/packages/wyatt_analysis/lib/analysis_options.2.4.3.yaml b/packages/wyatt_analysis/lib/analysis_options.2.4.3.yaml new file mode 100644 index 00000000..f471a727 --- /dev/null +++ b/packages/wyatt_analysis/lib/analysis_options.2.4.3.yaml @@ -0,0 +1,219 @@ +# 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 . + +analyzer: + language: + strict-casts: true + strict-inference: true + strict-raw-types: true + + errors: + todo: ignore + close_sinks: ignore + missing_required_param: error + missing_return: error + + exclude: + - lib/l10n/** + - lib/generated/** + - lib/gen/** + - lib/generated_plugin_registrant.dart + - test/.test_coverage.dart + - "**/*.g.dart" + - "**/*.freezed.dart" + +linter: + rules: + - always_declare_return_types + - always_put_control_body_on_new_line + - always_put_required_named_parameters_first + - always_require_non_null_named_parameters + - always_use_package_imports + - annotate_overrides + - avoid_bool_literals_in_conditional_expressions + - avoid_catching_errors + - avoid_double_and_int_checks + - avoid_dynamic_calls + - avoid_empty_else + - avoid_equals_and_hash_code_on_mutable_classes + - avoid_escaping_inner_quotes + - avoid_field_initializers_in_const_classes + - avoid_final_parameters + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_js_rounded_ints + - avoid_multiple_declarations_per_line + - avoid_null_checks_in_equality_operators + - avoid_positional_boolean_parameters + - avoid_private_typedef_functions + - avoid_redundant_argument_values + - avoid_relative_lib_imports + - avoid_renaming_method_parameters + - avoid_return_types_on_setters + - avoid_returning_null + - avoid_returning_null_for_future + - avoid_returning_null_for_void + - avoid_returning_this + - avoid_setters_without_getters + - avoid_shadowing_type_parameters + - avoid_single_cascade_in_expression_statements + - avoid_slow_async_io + - avoid_type_to_string + - avoid_types_as_parameter_names + - avoid_types_on_closure_parameters + - avoid_unused_constructor_parameters + - avoid_void_async + - await_only_futures + - camel_case_extensions + - camel_case_types + - cancel_subscriptions + - cascade_invocations + - cast_nullable_to_non_nullable + - collection_methods_unrelated_type + - combinators_ordering + - comment_references + - conditional_uri_does_not_exist + - constant_identifier_names + - control_flow_in_finally + - curly_braces_in_flow_control_structures + - dangling_library_doc_comments + - depend_on_referenced_packages + - deprecated_consistency + - directives_ordering + - empty_catches + - empty_constructor_bodies + - empty_statements + - eol_at_end_of_file + - exhaustive_cases + - file_names + - flutter_style_todos + - hash_and_equals + - implementation_imports + - implicit_call_tearoffs + - iterable_contains_unrelated_type + - join_return_with_assignment + - leading_newlines_in_multiline_strings + - library_names + - library_prefixes + - library_private_types_in_public_api + - lines_longer_than_80_chars + - list_remove_unrelated_type + - literal_only_boolean_expressions + - missing_whitespace_between_adjacent_strings + - no_adjacent_strings_in_list + - no_default_cases + - no_duplicate_case_values + - no_leading_underscores_for_library_prefixes + - no_leading_underscores_for_local_identifiers + - no_runtimeType_toString + - non_constant_identifier_names + - noop_primitive_operations + - null_check_on_nullable_type_parameter + - null_closures + - one_member_abstracts + - only_throw_errors + - overridden_fields + - package_api_docs + - package_names + - package_prefixed_library_names + - parameter_assignments + - prefer_adjacent_string_concatenation + - prefer_asserts_in_initializer_lists + - prefer_asserts_with_message + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_const_constructors + - prefer_const_constructors_in_immutables + - prefer_const_declarations + - prefer_const_literals_to_create_immutables + - prefer_constructors_over_static_methods + - prefer_contains + - prefer_equal_for_default_values + - prefer_expression_function_bodies + - prefer_final_fields + - prefer_final_in_for_each + - prefer_final_locals + - prefer_for_elements_to_map_fromIterable + - prefer_function_declarations_over_variables + - prefer_generic_function_type_aliases + - prefer_if_elements_to_conditional_expressions + - prefer_if_null_operators + - prefer_initializing_formals + - prefer_inlined_adds + - prefer_int_literals + - prefer_interpolation_to_compose_strings + - prefer_is_empty + - prefer_is_not_empty + - prefer_is_not_operator + - prefer_iterable_whereType + - prefer_mixin + - prefer_null_aware_method_calls + - prefer_null_aware_operators + - prefer_single_quotes + - prefer_spread_collections + - prefer_typing_uninitialized_variables + - prefer_void_to_null + - provide_deprecation_message + - recursive_getters + - require_trailing_commas + - slash_for_doc_comments + - sort_constructors_first + - sort_pub_dependencies + - sort_unnamed_constructors_first + - test_types_in_equals + - throw_in_finally + - tighten_type_of_initializing_formals + - type_annotate_public_apis + - type_init_formals + - unawaited_futures + - unnecessary_await_in_return + - unnecessary_brace_in_string_interps + - unnecessary_const + - unnecessary_constructor_name + - unnecessary_getters_setters + - unnecessary_lambdas + - unnecessary_late + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_null_checks + - unnecessary_null_in_if_null_operators + - unnecessary_nullable_for_final_variable_declarations + - unnecessary_overrides + - unnecessary_parenthesis + - unnecessary_raw_strings + - unnecessary_statements + - unnecessary_string_escapes + - unnecessary_string_interpolations + - unnecessary_this + - unnecessary_to_list_in_spreads + - unrelated_type_equality_checks + - unsafe_html + - use_enums + - use_function_type_syntax_for_parameters + - use_if_null_to_convert_nulls_to_bools + - use_is_even_rather_than_modulo + - use_late_for_private_fields_and_variables + - use_named_constants + - use_raw_strings + - use_rethrow_when_possible + - use_setters_to_change_properties + - use_string_buffers + - use_string_in_part_of_directives + - use_super_parameters + - use_test_throws_matchers + - use_to_and_as_if_applicable + - valid_regexps + - void_checks diff --git a/packages/wyatt_analysis/lib/analysis_options.flutter.2.4.2.yaml b/packages/wyatt_analysis/lib/analysis_options.flutter.2.4.2.yaml new file mode 100644 index 00000000..6a6224d1 --- /dev/null +++ b/packages/wyatt_analysis/lib/analysis_options.flutter.2.4.2.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 . + +include: package:wyatt_analysis/analysis_options.2.4.2.yaml + +linter: + rules: + - avoid_print + - avoid_unnecessary_containers + - avoid_web_libraries_in_flutter + - no_logic_in_create_state + - sized_box_for_whitespace + - sized_box_shrink_expand + - sort_child_properties_last + - use_build_context_synchronously + - use_colored_box + - use_decorated_box + - use_full_hex_values_for_flutter_colors + - use_key_in_widget_constructors diff --git a/packages/wyatt_analysis/lib/analysis_options.flutter.2.4.3.yaml b/packages/wyatt_analysis/lib/analysis_options.flutter.2.4.3.yaml new file mode 100644 index 00000000..ed1ddc29 --- /dev/null +++ b/packages/wyatt_analysis/lib/analysis_options.flutter.2.4.3.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 . + +include: package:wyatt_analysis/analysis_options.2.4.3.yaml + +linter: + rules: + - avoid_print + - avoid_unnecessary_containers + - avoid_web_libraries_in_flutter + - no_logic_in_create_state + - sized_box_for_whitespace + - sized_box_shrink_expand + - sort_child_properties_last + - use_build_context_synchronously + - use_colored_box + - use_decorated_box + - use_full_hex_values_for_flutter_colors + - use_key_in_widget_constructors diff --git a/packages/wyatt_analysis/lib/analysis_options.flutter.yaml b/packages/wyatt_analysis/lib/analysis_options.flutter.yaml index acb4b152..2d38d5b2 100644 --- a/packages/wyatt_analysis/lib/analysis_options.flutter.yaml +++ b/packages/wyatt_analysis/lib/analysis_options.flutter.yaml @@ -14,4 +14,4 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -include: package:wyatt_analysis/analysis_options.flutter.2.4.1.yaml +include: package:wyatt_analysis/analysis_options.flutter.2.4.3.yaml diff --git a/packages/wyatt_analysis/lib/analysis_options.yaml b/packages/wyatt_analysis/lib/analysis_options.yaml index 247b8c81..61266af2 100644 --- a/packages/wyatt_analysis/lib/analysis_options.yaml +++ b/packages/wyatt_analysis/lib/analysis_options.yaml @@ -14,4 +14,4 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -include: package:wyatt_analysis/analysis_options.2.4.1.yaml +include: package:wyatt_analysis/analysis_options.2.4.3.yaml diff --git a/packages/wyatt_analysis/lib/wyatt_analysis.dart b/packages/wyatt_analysis/lib/wyatt_analysis.dart index 6e1cf545..ccb06017 100644 --- a/packages/wyatt_analysis/lib/wyatt_analysis.dart +++ b/packages/wyatt_analysis/lib/wyatt_analysis.dart @@ -18,4 +18,4 @@ /// used internally at [Wyatt Studio](https://wyatt-studio.fr). library wyatt_analysis; -const String wyattAnalysisVersion = '2.4.1'; +const String wyattAnalysisVersion = '2.4.3'; diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_app_bar.g.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_app_bar.g.dart index ca934616..bbe73b13 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_app_bar.g.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_app_bar.g.dart @@ -88,6 +88,7 @@ class $CustomAppBarCWProxyImpl implements $TopAppBarComponentCWProxy { Key? key, }) => CustomAppBar( + key: key ?? _value.key, title: title ?? _value.title, ); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_bottom_bar.g.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_bottom_bar.g.dart index 68648c38..463d310f 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_bottom_bar.g.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_bottom_bar.g.dart @@ -24,7 +24,9 @@ class $CustomBottomBarCWProxyImpl int? currentIndex, Key? key, }) => - CustomBottomBar(); + CustomBottomBar( + key: key ?? _value.key, + ); } mixin $CustomBottomBarCWMixin on Component { diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.dart index bbd5ee99..40952513 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.dart @@ -5,13 +5,12 @@ import 'package:wyatt_ui_components/wyatt_ui_components.dart'; part 'custom_error_widget.g.dart'; @ComponentCopyWithExtension() -class CustomErrorWidget extends ErrorWidgetComponent - with $CustomErrorWidgetCWMixin { - CustomErrorWidget({super.key, super.error}); +class CustomErrorWidget extends ErrorComponent with $CustomErrorWidgetCWMixin { + const CustomErrorWidget({super.key, super.details}); @override Widget build(BuildContext context) => ColoredBox( color: Colors.red, - child: Center(child: Text(error?.data ?? 'Error')), + child: Center(child: Text(details?.data ?? 'Error')), ); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.g.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.g.dart index 64db5487..16a49808 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.g.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_error_widget.g.dart @@ -6,24 +6,36 @@ part of 'custom_error_widget.dart'; // ComponentCopyWithGenerator // ************************************************************************** -class $CustomErrorWidgetCWProxyImpl implements $ErrorWidgetComponentCWProxy { +class $CustomErrorWidgetCWProxyImpl implements $ErrorComponentCWProxy { const $CustomErrorWidgetCWProxyImpl(this._value); final CustomErrorWidget _value; @override - CustomErrorWidget error(TextWrapper? error) => this(error: error); + CustomErrorWidget colors(MultiColor? colors) => this(colors: colors); + @override + CustomErrorWidget message(TextWrapper? message) => this(message: message); + @override + CustomErrorWidget details(TextWrapper? details) => this(details: details); + @override + CustomErrorWidget themeResolver( + ThemeResolver? themeResolver) => + this(themeResolver: themeResolver); @override CustomErrorWidget key(Key? key) => this(key: key); @override CustomErrorWidget call({ - TextWrapper? error, + MultiColor? colors, + TextWrapper? message, + TextWrapper? details, + ThemeResolver? themeResolver, Key? key, }) => CustomErrorWidget( - error: error ?? _value.error, + key: key ?? _value.key, + details: details ?? _value.details, ); } mixin $CustomErrorWidgetCWMixin on Component { - $ErrorWidgetComponentCWProxy get copyWith => + $ErrorComponentCWProxy get copyWith => $CustomErrorWidgetCWProxyImpl(this as CustomErrorWidget); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.dart index bfc75ab2..c996a351 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.dart @@ -5,11 +5,14 @@ import 'package:wyatt_ui_components/wyatt_ui_components.dart'; part 'custom_loading_widget.g.dart'; @ComponentCopyWithExtension() -class CustomLoadingWidget extends LoadingWidgetComponent +class CustomLoadingWidget extends LoaderComponent with $CustomLoadingWidgetCWMixin { - CustomLoadingWidget({super.key, super.color}); + const CustomLoadingWidget({super.key, super.colors}); @override - Widget build(BuildContext context) => - Center(child: CircularProgressIndicator(color: color)); + Widget build(BuildContext context) => Center( + child: CircularProgressIndicator( + color: (colors?.isColor ?? false) ? colors!.color : Colors.blue, + ), + ); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.g.dart b/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.g.dart index 55a2ecb3..dfb8ace2 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.g.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/custom_loading_widget.g.dart @@ -6,25 +6,42 @@ part of 'custom_loading_widget.dart'; // ComponentCopyWithGenerator // ************************************************************************** -class $CustomLoadingWidgetCWProxyImpl - implements $LoadingWidgetComponentCWProxy { +class $CustomLoadingWidgetCWProxyImpl implements $LoaderComponentCWProxy { const $CustomLoadingWidgetCWProxyImpl(this._value); final CustomLoadingWidget _value; @override - CustomLoadingWidget color(Color? color) => this(color: color); + CustomLoadingWidget colors(MultiColor? colors) => this(colors: colors); + @override + CustomLoadingWidget radius(double? radius) => this(radius: radius); + @override + CustomLoadingWidget stroke(double? stroke) => this(stroke: stroke); + @override + CustomLoadingWidget duration(Duration? duration) => this(duration: duration); + @override + CustomLoadingWidget flip(bool? flip) => this(flip: flip); + @override + CustomLoadingWidget themeResolver( + ThemeResolver? themeResolver) => + this(themeResolver: themeResolver); @override CustomLoadingWidget key(Key? key) => this(key: key); @override CustomLoadingWidget call({ - Color? color, + MultiColor? colors, + double? radius, + double? stroke, + Duration? duration, + bool? flip, + ThemeResolver? themeResolver, Key? key, }) => CustomLoadingWidget( - color: color ?? _value.color, + key: key ?? _value.key, + colors: colors ?? _value.colors, ); } mixin $CustomLoadingWidgetCWMixin on Component { - $LoadingWidgetComponentCWProxy get copyWith => + $LoaderComponentCWProxy get copyWith => $CustomLoadingWidgetCWProxyImpl(this as CustomLoadingWidget); } diff --git a/packages/wyatt_bloc_layout/example/lib/components/theme_components.dart b/packages/wyatt_bloc_layout/example/lib/components/theme_components.dart index afc4203d..888522dd 100644 --- a/packages/wyatt_bloc_layout/example/lib/components/theme_components.dart +++ b/packages/wyatt_bloc_layout/example/lib/components/theme_components.dart @@ -4,11 +4,11 @@ import 'package:bloc_layout_example/components/custom_error_widget.dart'; import 'package:bloc_layout_example/components/custom_loading_widget.dart'; import 'package:wyatt_ui_components/wyatt_ui_components.dart'; -class AppThemeComponent { - static ComponentThemeData get components => ComponentThemeData.raw( - appBar: const CustomAppBar(), - bottomNavigationBar: const CustomBottomBar(), - loadingWidget: CustomLoadingWidget(), - errorWidget: CustomErrorWidget(), - ); +abstract class AppThemeComponent { + static const ComponentThemeData components = ComponentThemeData.raw( + topAppBar: CustomAppBar(), + bottomNavigationBar: CustomBottomBar(), + loader: CustomLoadingWidget(), + error: CustomErrorWidget(), + ); } diff --git a/packages/wyatt_bloc_layout/example/lib/main.dart b/packages/wyatt_bloc_layout/example/lib/main.dart index 2856aec7..ed7f9709 100644 --- a/packages/wyatt_bloc_layout/example/lib/main.dart +++ b/packages/wyatt_bloc_layout/example/lib/main.dart @@ -32,7 +32,7 @@ class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) => ComponentTheme( - componentThemeWidget: AppThemeComponent.components, + data: AppThemeComponent.components, child: MaterialApp( title: 'Bloc Layout Example', theme: ThemeData( @@ -122,7 +122,7 @@ class ExampleFrameLayoutCrudConsumer ExampleFrameLayoutCrudConsumer({super.key}) : super( customAppBar: (bar) => bar?.copyWith.title( - 'Example Title'.wrap(), + const TextWrapper('Example Title'), ), ); @@ -139,7 +139,7 @@ class ExampleFrameLayoutCrudListConsumer ExampleFrameLayoutCrudListConsumer({super.key}) : super( customAppBar: (bar) => bar?.copyWith.title( - 'Example Title'.wrap(), + const TextWrapper('Example Title'), ), ); diff --git a/packages/wyatt_bloc_layout/lib/src/core/crud_cubit_consumer_screen_mixin.dart b/packages/wyatt_bloc_layout/lib/src/core/crud_cubit_consumer_screen_mixin.dart index d55782e3..7a083f3c 100644 --- a/packages/wyatt_bloc_layout/lib/src/core/crud_cubit_consumer_screen_mixin.dart +++ b/packages/wyatt_bloc_layout/lib/src/core/crud_cubit_consumer_screen_mixin.dart @@ -23,11 +23,12 @@ import 'package:wyatt_ui_components/wyatt_ui_components.dart'; mixin CrudMixin, SuccessState extends CrudSuccess> { Widget errorBuilder(BuildContext context, CrudError state) => - context.components.errorWidget?.copyWith(error: state.message.wrap()) ?? - const SizedBox.shrink(); + context.components.errorComponent.call( + message: (state.message != null) ? TextWrapper(state.message!) : null, + ); Widget loadingBuilder(BuildContext context, CrudLoading state) => - context.components.loadingWidget ?? const SizedBox.shrink(); + context.components.loader ?? const SizedBox.shrink(); Widget initialBuilder(BuildContext context, CrudInitial state) => const SizedBox.shrink(); diff --git a/packages/wyatt_component_copy_with_extension/lib/wyatt_component_copy_with_extension.dart b/packages/wyatt_component_copy_with_extension/lib/wyatt_component_copy_with_extension.dart index 9ba9c518..ba920e68 100644 --- a/packages/wyatt_component_copy_with_extension/lib/wyatt_component_copy_with_extension.dart +++ b/packages/wyatt_component_copy_with_extension/lib/wyatt_component_copy_with_extension.dart @@ -15,7 +15,7 @@ // along with this program. If not, see . /// Extension for component copy with feature -library component_copy_with_extension; +library wyatt_component_copy_with_extension; export './src/domain/domain.dart'; export 'src/component_copy_with_extension.dart'; diff --git a/packages/wyatt_component_copy_with_gen/build.yaml b/packages/wyatt_component_copy_with_gen/build.yaml index 5d11aeaf..ec4b846d 100644 --- a/packages/wyatt_component_copy_with_gen/build.yaml +++ b/packages/wyatt_component_copy_with_gen/build.yaml @@ -1,7 +1,7 @@ targets: $default: builders: - component_copy_with_gen: + wyatt_component_copy_with_gen: enabled: true generate_for: exclude: @@ -11,9 +11,9 @@ targets: - test/gen_* builders: - component_copy_with_gen: - target: ":component_copy_with_gen" - import: "package:wyatt_component_copy_with_gen/component_copy_with_gen.dart" + wyatt_component_copy_with_gen: + target: ":wyatt_component_copy_with_gen" + import: "package:wyatt_component_copy_with_gen/wyatt_component_copy_with_gen.dart" builder_factories: ["componentCopyWithReporter"] build_extensions: { ".dart": ["copy_with_extension_gen.g.part"] } auto_apply: dependents diff --git a/packages/wyatt_component_copy_with_gen/lib/wyatt_component_copy_with_gen.dart b/packages/wyatt_component_copy_with_gen/lib/wyatt_component_copy_with_gen.dart index 6e51cdd6..3ae2761e 100644 --- a/packages/wyatt_component_copy_with_gen/lib/wyatt_component_copy_with_gen.dart +++ b/packages/wyatt_component_copy_with_gen/lib/wyatt_component_copy_with_gen.dart @@ -15,7 +15,7 @@ // along with this program. If not, see . /// Generator for copywith method for components -library component_copy_with_gen; +library wyatt_component_copy_with_gen; export 'src/builder.dart'; export 'src/generators/component_copy_with_generator.dart'; diff --git a/packages/wyatt_ui_components/README.md b/packages/wyatt_ui_components/README.md index 5fedb940..dbff11f0 100644 --- a/packages/wyatt_ui_components/README.md +++ b/packages/wyatt_ui_components/README.md @@ -99,6 +99,12 @@ If you need specific settings, or pass parameters to your component, call `copyW ) ``` +## Default implementation + +To use this package, you have to create your own implementation of the components. You can check out [Wyatt UI Kit](https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_ui_kit) package for an example. + +But default theme extensions (used in all implementations as fallback for styles) are available in `lib/src/domain/theme_extensions` folder. + ## Development > Common to this, and Wyatt UI Kit packages. diff --git a/packages/wyatt_ui_components/build.yaml b/packages/wyatt_ui_components/build.yaml index 2c112259..5b42632a 100644 --- a/packages/wyatt_ui_components/build.yaml +++ b/packages/wyatt_ui_components/build.yaml @@ -2,8 +2,8 @@ targets: $default: builders: # Typically the builder key is just the package name, run `pub run build_runner doctor` to check your config. - wyatt_component_copy_with_gen:component_copy_with_gen: + wyatt_component_copy_with_gen:wyatt_component_copy_with_gen: generate_for: # Example glob for only the Dart files under `lib/models` - lib/**/*.dart - - example/lib/**/*.dart \ No newline at end of file + - example/lib/**/*.dart diff --git a/packages/wyatt_ui_components/example/lib/component_theme.dart b/packages/wyatt_ui_components/example/lib/component_theme.dart index 4641a1b2..258dfd0e 100644 --- a/packages/wyatt_ui_components/example/lib/component_theme.dart +++ b/packages/wyatt_ui_components/example/lib/component_theme.dart @@ -2,13 +2,13 @@ import 'package:wyatt_ui_components/wyatt_ui_components.dart'; import 'package:wyatt_ui_components_example/components/custom_app_bar.dart'; import 'package:wyatt_ui_components_example/components/custom_bottom_bar.dart'; import 'package:wyatt_ui_components_example/components/custom_error_widget.dart'; -import 'package:wyatt_ui_components_example/components/custom_loading_widget.dart'; +import 'package:wyatt_ui_components_example/components/custom_loader_widget.dart'; class AppThemeComponent { static ComponentThemeData get components => const ComponentThemeData.raw( - appBar: CustomAppBar(), + topAppBar: CustomAppBar(), bottomNavigationBar: CustomBottomNavigationBar(), - errorWidget: CustomErrorWidget(), - loadingWidget: CustomLoadingWidget(), + error: CustomErrorWidget(), + loader: CustomLoaderWidget(), ); } 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 cd7fc7d3..5362dbb2 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 @@ -5,13 +5,17 @@ import 'package:wyatt_ui_components/wyatt_ui_components.dart'; part 'custom_error_widget.g.dart'; @ComponentCopyWithExtension() -class CustomErrorWidget extends ErrorWidgetComponent - with $CustomErrorWidgetCWMixin { - const CustomErrorWidget({super.error, super.key}); +class CustomErrorWidget extends ErrorComponent with $CustomErrorWidgetCWMixin { + const CustomErrorWidget({ + super.colors, + super.message, + super.details, + super.key, + }); @override Widget build(BuildContext context) => ColoredBox( - color: Colors.red, - child: Center(child: Text(error?.data ?? 'Error')), + color: colors?.color ?? Colors.red, + child: Center(child: Text(message?.data ?? '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 index ae1e64dd..0c9f059c 100644 --- 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 @@ -6,25 +6,38 @@ part of 'custom_error_widget.dart'; // ComponentCopyWithGenerator // ************************************************************************** -class $CustomErrorWidgetCWProxyImpl implements $ErrorWidgetComponentCWProxy { +class $CustomErrorWidgetCWProxyImpl implements $ErrorComponentCWProxy { const $CustomErrorWidgetCWProxyImpl(this._value); final CustomErrorWidget _value; @override - CustomErrorWidget error(TextWrapper? error) => this(error: error); + CustomErrorWidget colors(MultiColor? colors) => this(colors: colors); + @override + CustomErrorWidget message(TextWrapper? message) => this(message: message); + @override + CustomErrorWidget details(TextWrapper? details) => this(details: details); + @override + CustomErrorWidget themeResolver( + ThemeResolver? themeResolver) => + this(themeResolver: themeResolver); @override CustomErrorWidget key(Key? key) => this(key: key); @override CustomErrorWidget call({ - TextWrapper? error, + MultiColor? colors, + TextWrapper? message, + TextWrapper? details, + ThemeResolver? themeResolver, Key? key, }) => CustomErrorWidget( - error: error ?? _value.error, + colors: colors ?? _value.colors, + message: message ?? _value.message, + details: details ?? _value.details, key: key ?? _value.key, ); } mixin $CustomErrorWidgetCWMixin on Component { - $ErrorWidgetComponentCWProxy get copyWith => + $ErrorComponentCWProxy 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_loader_widget.dart similarity index 53% rename from packages/wyatt_ui_components/example/lib/components/custom_loading_widget.dart rename to packages/wyatt_ui_components/example/lib/components/custom_loader_widget.dart index 2c7489f6..0167ce60 100644 --- a/packages/wyatt_ui_components/example/lib/components/custom_loading_widget.dart +++ b/packages/wyatt_ui_components/example/lib/components/custom_loader_widget.dart @@ -2,17 +2,24 @@ import 'package:flutter/material.dart'; import 'package:wyatt_component_copy_with_extension/wyatt_component_copy_with_extension.dart'; import 'package:wyatt_ui_components/wyatt_ui_components.dart'; -part 'custom_loading_widget.g.dart'; +part 'custom_loader_widget.g.dart'; @ComponentCopyWithExtension() -class CustomLoadingWidget extends LoadingWidgetComponent - with $CustomLoadingWidgetCWMixin { - const CustomLoadingWidget({super.color, super.key}); +class CustomLoaderWidget extends LoaderComponent + with $CustomLoaderWidgetCWMixin { + const CustomLoaderWidget({ + super.colors, + super.duration, + super.flip, + super.radius, + super.stroke, + super.key, + }); @override Widget build(BuildContext context) => Center( child: CircularProgressIndicator( - color: color, + color: colors?.color ?? Colors.blue, ), ); } diff --git a/packages/wyatt_ui_components/example/lib/components/custom_loader_widget.g.dart b/packages/wyatt_ui_components/example/lib/components/custom_loader_widget.g.dart new file mode 100644 index 00000000..737d8967 --- /dev/null +++ b/packages/wyatt_ui_components/example/lib/components/custom_loader_widget.g.dart @@ -0,0 +1,51 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'custom_loader_widget.dart'; + +// ************************************************************************** +// ComponentCopyWithGenerator +// ************************************************************************** + +class $CustomLoaderWidgetCWProxyImpl implements $LoaderComponentCWProxy { + const $CustomLoaderWidgetCWProxyImpl(this._value); + final CustomLoaderWidget _value; + @override + CustomLoaderWidget colors(MultiColor? colors) => this(colors: colors); + @override + CustomLoaderWidget radius(double? radius) => this(radius: radius); + @override + CustomLoaderWidget stroke(double? stroke) => this(stroke: stroke); + @override + CustomLoaderWidget duration(Duration? duration) => this(duration: duration); + @override + CustomLoaderWidget flip(bool? flip) => this(flip: flip); + @override + CustomLoaderWidget themeResolver( + ThemeResolver? themeResolver) => + this(themeResolver: themeResolver); + @override + CustomLoaderWidget key(Key? key) => this(key: key); + @override + CustomLoaderWidget call({ + MultiColor? colors, + double? radius, + double? stroke, + Duration? duration, + bool? flip, + ThemeResolver? themeResolver, + Key? key, + }) => + CustomLoaderWidget( + colors: colors ?? _value.colors, + duration: duration ?? _value.duration, + flip: flip ?? _value.flip, + radius: radius ?? _value.radius, + stroke: stroke ?? _value.stroke, + key: key ?? _value.key, + ); +} + +mixin $CustomLoaderWidgetCWMixin on Component { + $LoaderComponentCWProxy get copyWith => + $CustomLoaderWidgetCWProxyImpl(this as CustomLoaderWidget); +} 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 deleted file mode 100644 index a6e78666..00000000 --- a/packages/wyatt_ui_components/example/lib/components/custom_loading_widget.g.dart +++ /dev/null @@ -1,31 +0,0 @@ -// 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 6c982b98..be86f9b0 100644 --- a/packages/wyatt_ui_components/example/lib/main.dart +++ b/packages/wyatt_ui_components/example/lib/main.dart @@ -28,7 +28,7 @@ class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) => ComponentTheme( - componentThemeWidget: AppThemeComponent.components, + data: AppThemeComponent.components, child: MaterialApp( title: 'Wyatt Ui Components Example', theme: ThemeData( @@ -48,24 +48,23 @@ class Home extends StatelessWidget { Widget build(BuildContext context) => Scaffold( appBar: PreferredSize( preferredSize: const Size.fromHeight(60), - child: context.components.appBar?.copyWith - .title('Example title'.wrap()) ?? - const SizedBox.shrink(), + child: context.components.topAppBarComponent + .title(const TextWrapper('Example title')), ), body: Column( children: [ Expanded( - child: context.components.errorWidget - ?.copyWith(error: 'Example erreur'.wrap()) ?? - const SizedBox.shrink(), + child: context.components.errorComponent.call( + message: const TextWrapper('Example error'), + ), ), const SizedBox( height: 10, ), Expanded( - child: context.components.loadingWidget - ?.copyWith(color: Colors.green) ?? - const SizedBox.shrink(), + child: context.components.loaderComponent.call( + colors: const MultiColor.single(Colors.green), + ), ), ], ), diff --git a/packages/wyatt_ui_components/lib/src/core/core.dart b/packages/wyatt_ui_components/lib/src/core/core.dart index 50874264..e4df47c7 100644 --- a/packages/wyatt_ui_components/lib/src/core/core.dart +++ b/packages/wyatt_ui_components/lib/src/core/core.dart @@ -16,6 +16,5 @@ export 'enums/enums.dart'; export 'extensions/build_context_extensions.dart'; -export 'extensions/string_extension.dart'; export 'mixins/copy_with_mixin.dart'; export 'utils/utils.dart'; diff --git a/packages/wyatt_ui_components/lib/src/core/utils/gradient_helper.dart b/packages/wyatt_ui_components/lib/src/core/utils/gradient_helper.dart new file mode 100644 index 00000000..740d9281 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/core/utils/gradient_helper.dart @@ -0,0 +1,38 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import 'package:flutter/material.dart'; +import 'package:wyatt_ui_components/wyatt_ui_components.dart'; + +abstract class GradientHelper { + static LinearGradient? linearFromNullableColors(List? colors) => + colors != null ? LinearGradient(colors: colors) : null; + + static LinearGradient? linearFromMultiColor(MultiColor multiColor) => + multiColor.isGradient ? LinearGradient(colors: multiColor.colors) : null; + + static RadialGradient? radialFromNullableColors(List? colors) => + colors != null ? RadialGradient(colors: colors) : null; + + static RadialGradient? radialFromMultiColor(MultiColor multiColor) => + multiColor.isGradient ? RadialGradient(colors: multiColor.colors) : null; + + static SweepGradient? sweepFromNullableColors(List? colors) => + colors != null ? SweepGradient(colors: colors) : null; + + static SweepGradient? sweepFromMultiColor(MultiColor multiColor) => + multiColor.isGradient ? SweepGradient(colors: multiColor.colors) : null; +} diff --git a/packages/wyatt_ui_components/lib/src/core/utils/text_wrapper.dart b/packages/wyatt_ui_components/lib/src/core/utils/text_wrapper.dart index 2c6e248e..35318908 100644 --- a/packages/wyatt_ui_components/lib/src/core/utils/text_wrapper.dart +++ b/packages/wyatt_ui_components/lib/src/core/utils/text_wrapper.dart @@ -36,15 +36,28 @@ class TextWrapper { }); /// Creates a [TextWrapper] from a [Text] widget. - const TextWrapper.text(this.data) - : style = null, + TextWrapper.text(Text text) + : data = text.data!, + style = text.style, gradientColors = null, - textAlign = null, - textDirection = null, - softWrap = null, - overflow = null, - maxLines = null, - selectionColor = null; + textAlign = text.textAlign, + textDirection = text.textDirection, + softWrap = text.softWrap, + overflow = text.overflow, + maxLines = text.maxLines, + selectionColor = text.selectionColor; + + /// Creates a [TextWrapper] from a [RichText] widget. + TextWrapper.rich(RichText richText) + : data = richText.text.toPlainText(), + style = richText.text.style, + gradientColors = null, + textAlign = richText.textAlign, + textDirection = richText.textDirection, + softWrap = richText.softWrap, + overflow = richText.overflow, + maxLines = richText.maxLines, + selectionColor = richText.selectionColor; /// Text to be displayed final String data; @@ -108,4 +121,7 @@ class TextWrapper { /// that, the selection color defaults to [DefaultSelectionStyle.defaultColor] /// (semi-transparent grey). final Color? selectionColor; + + @override + String toString() => data; } diff --git a/packages/wyatt_ui_components/lib/src/core/utils/theme_helper.dart b/packages/wyatt_ui_components/lib/src/core/utils/theme_helper.dart index 97fe94a0..5db92be8 100644 --- a/packages/wyatt_ui_components/lib/src/core/utils/theme_helper.dart +++ b/packages/wyatt_ui_components/lib/src/core/utils/theme_helper.dart @@ -14,35 +14,84 @@ // You should have received a copy of the GNU General Public License // along with super program. If not, see . +import 'package:flutter/material.dart'; + /// A helper class for getting theme elements. abstract class ThemeHelper { - /// Gets a theme element from a list of styles. + /// Gets a nullable theme element from a list of styles. + /// {@template getElement} /// Styles are checked in order, and the first one that passes the /// [valueValidator] is returned. /// Style elements are transformed using the [transform] function. /// - /// [styles]: A list of styles that need to be checked. - /// [transform]: A function that transforms each style element - /// to a [T] type. - /// [valueValidator]: An optional validation function that - /// determines if a style element is valid. - /// [combine]: A function that combines two [P] type objects to create - /// a new object. - static T? getThemeElement( + /// - [styles] : A list of styles that need to be checked. + /// + /// - [transform] : An optional function that transforms each style element + /// to a [T] type after it passes the [valueValidator]. *(default: returns + /// element as is)* + /// + /// - [valueValidator] : An optional validation function that + /// determines if a style element is valid. *(default: checks if element + /// is not null)* + /// + /// - [combine] : A function that combines two [P] type objects to create + /// a new object. *(default: returns the first element)* + /// + /// So, if you only pass a [styles] list, the first valid style element + /// will be returned as is. + /// If you pass a [transform] function, the first valid style element + /// will be transformed to a [T] type. + /// {@endtemplate} + static T? maybeGetElement( List? styles, { - required T? Function(P?)? transform, + T? Function(P?)? transform, bool? Function(P?)? valueValidator, P? Function(P?, P?)? combine, }) { + // List of valid styles final Iterable? validStyles = styles?.where( (element) => valueValidator?.call(element) ?? (element != null), ); + + // tranformation function + final transformation = transform ?? (element) => element as T?; + return (validStyles?.isNotEmpty ?? false) - ? transform?.call( + ? transformation.call( validStyles?.reduce( (value, element) => combine?.call(value, element) ?? value, ), ) : null; } + + /// Gets a theme element from a list of styles. Throws an exception if no + /// valid style is found. + /// + /// See [maybeGetElement] for more details. + /// + /// {@macro getElement} + static T getElement( + List? styles, { + T? Function(P?)? transform, + bool? Function(P?)? valueValidator, + P? Function(P?, P?)? combine, + }) { + final result = maybeGetElement( + styles, + transform: transform, + valueValidator: valueValidator, + combine: combine, + ); + + if (result == null) { + throw FlutterError( + 'No valid style found.\nPlease check your theme configuration.\n' + 'Searching for: $P in $styles (transform to $T)\n' + 'If this value can be null, use maybeGetElement instead.', + ); + } + + return result; + } } diff --git a/packages/wyatt_ui_kit/lib/src/core/helpers/linear_gradient_helper.dart b/packages/wyatt_ui_components/lib/src/core/utils/theme_importer.dart similarity index 58% rename from packages/wyatt_ui_kit/lib/src/core/helpers/linear_gradient_helper.dart rename to packages/wyatt_ui_components/lib/src/core/utils/theme_importer.dart index 49eb9c80..a5c5eae0 100644 --- a/packages/wyatt_ui_kit/lib/src/core/helpers/linear_gradient_helper.dart +++ b/packages/wyatt_ui_components/lib/src/core/utils/theme_importer.dart @@ -15,12 +15,25 @@ // along with this program. If not, see . import 'package:flutter/material.dart'; -import 'package:wyatt_ui_components/wyatt_ui_components.dart'; -class LinearGradientHelper { - static LinearGradient? fromNullableColors(List? colors) => - colors != null ? LinearGradient(colors: colors) : null; +abstract class ThemeImporter { + /// Imports a [ThemeData] from either a [BuildContext] or a [ThemeData]. + /// + /// Throws an [ArgumentError] if the type of [from] is not a [BuildContext] + /// or a [ThemeData]. + static ThemeData importFrom(T from) { + ThemeData theme; - static LinearGradient? fromMultiColor(MultiColor multiColor) => - multiColor.isGradient ? LinearGradient(colors: multiColor.colors) : null; + if (from is BuildContext) { + theme = Theme.of(from); + } else if (from is ThemeData) { + theme = from; + } else { + throw ArgumentError( + 'from must be either a BuildContext or a ThemeData', + ); + } + + return theme; + } } diff --git a/packages/wyatt_ui_components/lib/src/core/utils/theme_resolver.dart b/packages/wyatt_ui_components/lib/src/core/utils/theme_resolver.dart index a8cb2d1e..66e43f66 100644 --- a/packages/wyatt_ui_components/lib/src/core/utils/theme_resolver.dart +++ b/packages/wyatt_ui_components/lib/src/core/utils/theme_resolver.dart @@ -26,47 +26,82 @@ import 'package:wyatt_ui_components/src/domain/entities/theme_style.dart'; /// 1) Pass the "radius" into the constructor, `Component(radius: 12)`. /// 2) Set up a theme extension `ComponentThemeExtension(radius: 15)`. /// 3) Let `wyatt_ui_kit` "negotiate" and try to find a suitable style in the -/// flutter theme. +/// flutter theme, or use a hardcoded value. /// -/// If this negotiation phase fails, then: -/// - If the value is mandatory: a hardcoded value in "wyatt_ui_kit" is chosen. -/// - If not, the style is simply not applied. +/// If a negotiation phase fails, it will fallback to the next one. +/// +/// This resolver uses [ThemeHelper] to negotiate and merge styles. /// {@endtemplate} -abstract class ThemeResolver, T, E> { +abstract class ThemeResolver