diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b6f643..86ca0c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -## [4.13.0] - 2024-11-07 +## [4.14.0] - 2024-11-07 +- Added missing min value check. +- Fixed zero not being deleted if `showZeroValue` parameter is true.[23](https://github.com/IsaiasSantana/currency_textfield/issues/23) +- Bump flutter_lints to 5.0.0. + +## [4.13.0] - 2024-11-06 - Added `removeSymbol` parameter to let you define that controller will only show the formatted number. - Fixed tests. diff --git a/analysis_options.yaml b/analysis_options.yaml index f16eead..c3a942a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,109 @@ -include: package:flutter_lints/flutter.yaml +analyzer: + language: + + errors: + close_sinks: ignore + missing_required_param: error + record_literal_one_positional_no_trailing_comma: error + collection_methods_unrelated_type: warning + unrelated_type_equality_checks: warning + + exclude: + - test/.test_coverage.dart + - lib/generated_plugin_registrant.dart linter: - rules: \ No newline at end of file + rules: + - avoid_redundant_argument_values + - annotate_overrides + - avoid_bool_literals_in_conditional_expressions + - avoid_double_and_int_checks + - avoid_empty_else + - avoid_equals_and_hash_code_on_mutable_classes + - avoid_escaping_inner_quotes + - avoid_field_initializers_in_const_classes + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_js_rounded_ints + - avoid_private_typedef_functions + - avoid_relative_lib_imports + - avoid_renaming_method_parameters + - avoid_return_types_on_setters + - 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_unnecessary_containers + - avoid_unused_constructor_parameters + - avoid_void_async + - await_only_futures + - camel_case_extensions + - camel_case_types + - cancel_subscriptions + - 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 + - empty_catches + - empty_constructor_bodies + - empty_statements + - exhaustive_cases + - file_names + - hash_and_equals + - implicit_call_tearoffs + - implementation_imports + - implicit_reopen + - invalid_case_patterns + - join_return_with_assignment + - leading_newlines_in_multiline_strings + - library_annotations + - library_names + - library_prefixes + - no_default_cases + - sized_box_for_whitespace + - sized_box_shrink_expand + - slash_for_doc_comments + - sort_child_properties_last + - sort_unnamed_constructors_first + - test_types_in_equals + - throw_in_finally + - 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 + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_null_checks + - unnecessary_breaks + - unnecessary_brace_in_string_interps + - unnecessary_const + - prefer_const_literals_to_create_immutables + - prefer_constructors_over_static_methods + - prefer_contains + - prefer_final_in_for_each + - unnecessary_string_escapes + - unnecessary_null_in_if_null_operators + - unnecessary_nullable_for_final_variable_declarations + - unnecessary_overrides + - unnecessary_parenthesis + - unnecessary_to_list_in_spreads + - unrelated_type_equality_checks + - use_build_context_synchronously + - use_colored_box + - prefer_const_constructors + - prefer_const_constructors_in_immutables + - prefer_const_declarations \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index 292643d..73c0f1e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -31,7 +31,8 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - final CurrencyTextFieldController _controller = CurrencyTextFieldController(); + final CurrencyTextFieldController _controller = + CurrencyTextFieldController(showZeroValue: true); final CurrencyTextFieldController _controller2 = CurrencyTextFieldController( initDoubleValue: -10, currencySeparator: ' -> '); final CurrencyTextFieldController _controller3 = CurrencyTextFieldController( diff --git a/lib/currency_textfield.dart b/lib/currency_textfield.dart index f049043..5d00d53 100644 --- a/lib/currency_textfield.dart +++ b/lib/currency_textfield.dart @@ -171,7 +171,7 @@ class CurrencyTextFieldController extends TextEditingController { } if (text.isEmpty) { - _zeroValue(resetText: false); + _zeroValue(clean: _checkCleanZeroText(text)); return; } @@ -196,7 +196,8 @@ class CurrencyTextFieldController extends TextEditingController { } if ((double.tryParse(clearText) ?? 0.0) == 0.0) { - _zeroValue(forceNegative: text.endsWith('-')); + _zeroValue( + forceNegative: text.endsWith('-'), clean: _checkCleanZeroText(text)); return; } @@ -213,7 +214,7 @@ class CurrencyTextFieldController extends TextEditingController { } _value = _getDoubleValueFor(string: clearText); - + _checkMinValue(); _checkMaxValue(); @@ -345,11 +346,16 @@ class CurrencyTextFieldController extends TextEditingController { } ///resets the controller to 0. - void _zeroValue({bool resetText = true, bool forceNegative = false}) { + void _zeroValue({bool forceNegative = false, bool clean = false}) { + if (clean) { + _previewsText = ''; + text = _previewsText; + return; + } _value = 0; _isNegative = forceNegative; - if (resetText || _showZeroValue) { + if (_showZeroValue) { _changeText(); } else { _previewsText = ''; @@ -360,6 +366,12 @@ class CurrencyTextFieldController extends TextEditingController { } } + bool _checkCleanZeroText(String currentText) { + return _value == 0 && + _showZeroValue && + currentText.length < _previewsText.length; + } + String? _getOnlyNumbers({String? string}) => string?.replaceAll(_onlyNumbersRegex, ''); diff --git a/pubspec.lock b/pubspec.lock index 6c70b99..41d1dd2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -58,10 +58,10 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c" + sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "5.0.0" flutter_test: dependency: "direct dev" description: flutter @@ -95,10 +95,10 @@ packages: dependency: transitive description: name: lints - sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235" + sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "5.0.0" matcher: dependency: transitive description: @@ -201,5 +201,5 @@ packages: source: hosted version: "14.2.5" sdks: - dart: ">=3.3.0 <4.0.0" + dart: ">=3.5.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index b84711f..0fa7fd1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: currency_textfield description: A flutter package that implements a Controller for currency text input. -version: 4.13.0 +version: 4.14.0 homepage: https://github.com/IsaiasSantana/currency_textfield environment: sdk: '>=3.0.0 <4.0.0' @@ -10,5 +10,5 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^4.0.0 + flutter_lints: ^5.0.0 flutter: