diff --git a/CHANGELOG.md b/CHANGELOG.md index e449c20..f47bbf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.2.0] - XX/XX/2026 + +* Replace dart_style with `dart format` to help compatibility with newer Flutter versions. + ## [2.1.0] - 20/10/2024 * Set Dart 3 as minimum constraint diff --git a/example/pubspec.lock b/example/pubspec.lock index b5b4531..6f1c183 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,22 +1,6 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - _fe_analyzer_shared: - dependency: transitive - description: - name: _fe_analyzer_shared - sha256: a36ec4843dc30ea6bf652bf25e3448db6c5e8bcf4aa55f063a5d1dad216d8214 - url: "https://pub.dev" - source: hosted - version: "58.0.0" - analyzer: - dependency: transitive - description: - name: analyzer - sha256: cc4242565347e98424ce9945c819c192ec0838cb9d1f6aa4a97cc96becbc5b27 - url: "https://pub.dev" - source: hosted - version: "5.10.0" arb_generator: dependency: transitive description: @@ -33,22 +17,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.3.6" - args: - dependency: transitive - description: - name: args - sha256: "4cab82a83ffef80b262ddedf47a0a8e56ee6fbf7fe21e6e768b02792034dd440" - url: "https://pub.dev" - source: hosted - version: "2.4.0" - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" characters: dependency: transitive description: @@ -105,14 +73,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.5" - dart_style: - dependency: transitive - description: - name: dart_style - sha256: "6d691edde054969f0e0f26abb1b30834b5138b963793e56f69d3a9a4435e6352" - url: "https://pub.dev" - source: hosted - version: "2.3.0" equatable: dependency: transitive description: @@ -129,21 +89,13 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" - file: - dependency: transitive - description: - name: file - sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" - url: "https://pub.dev" - source: hosted - version: "6.1.4" flappy_translator: dependency: "direct dev" description: path: ".." relative: true source: path - version: "2.0.0" + version: "2.1.0" flutter: dependency: "direct main" description: flutter @@ -162,14 +114,6 @@ packages: description: flutter source: sdk version: "0.0.0" - glob: - dependency: transitive - description: - name: glob - sha256: "4515b5b6ddb505ebdd242a5f2cc5d22d3d6a80013789debfbda7777f47ea308c" - url: "https://pub.dev" - source: hosted - version: "2.1.1" intl: dependency: transitive description: @@ -210,14 +154,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.9.1" - package_config: - dependency: transitive - description: - name: package_config - sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" - url: "https://pub.dev" - source: hosted - version: "2.1.0" path: dependency: transitive description: @@ -242,14 +178,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.7.2" - pub_semver: - dependency: transitive - description: - name: pub_semver - sha256: "307de764d305289ff24ad257ad5c5793ce56d04947599ad68b3baa124105fc17" - url: "https://pub.dev" - source: hosted - version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -295,14 +223,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - watcher: - dependency: transitive - description: - name: watcher - sha256: "6a7f46926b01ce81bfc339da6a7f20afbe7733eff9846f6d6a5466aa4c6667c0" - url: "https://pub.dev" - source: hosted - version: "1.0.2" xml: dependency: transitive description: diff --git a/lib/src/services/code_generation/code_generator.dart b/lib/src/services/code_generation/code_generator.dart index 4fbccb6..80365ff 100644 --- a/lib/src/services/code_generation/code_generator.dart +++ b/lib/src/services/code_generation/code_generator.dart @@ -1,5 +1,3 @@ -import 'package:dart_style/dart_style.dart'; - import '../../configs/constants.dart' as constants; import '../../configs/default_settings.dart'; import '../../extensions/list_extensions.dart'; @@ -19,8 +17,8 @@ class CodeGenerator { late String _fields; late List _supportedLanguages; - /// Returns a string formatted according to default dart rules - String get formattedString => DartFormatter().format(_template); + /// Returns the generated code as a non-formatted String + String get fileContents => _template; CodeGenerator({ String className = DefaultSettings.className, diff --git a/lib/src/services/code_generation/template.dart b/lib/src/services/code_generation/template.dart index d2dac03..8388584 100644 --- a/lib/src/services/code_generation/template.dart +++ b/lib/src/services/code_generation/template.dart @@ -27,8 +27,7 @@ class #CLASS_NAME# { static #CLASS_NAME# of(BuildContext context) => Localizations.of<#CLASS_NAME#>(context, #CLASS_NAME#)!; - String _getText(String key) => - _localizedValues[key] ?? '** \$key not found'; + String _getText(String key) => _localizedValues[key] ?? '** \$key not found'; Locale get currentLocale => _locale; @@ -43,8 +42,7 @@ class #CLASS_NAME# { static late Locale _locale; - static String _getText(String key) => - _localizedValues[key] ?? '** \$key not found'; + static String _getText(String key) => _localizedValues[key] ?? '** \$key not found'; static Locale get currentLocale => _locale; @@ -108,7 +106,6 @@ class #CLASS_NAME#Delegate extends LocalizationsDelegate<#CLASS_NAME#> { @override bool shouldReload(#CLASS_NAME#Delegate old) => false; } - '''; } diff --git a/lib/src/services/flappy_translator.dart b/lib/src/services/flappy_translator.dart index 1f5f93b..64b9f64 100644 --- a/lib/src/services/flappy_translator.dart +++ b/lib/src/services/flappy_translator.dart @@ -88,12 +88,12 @@ class FlappyTranslator { codeGenerator.finalize(); - // format the contents according to dart defaults - final formattedString = codeGenerator.formattedString; - // write output file final path = outputDir.isEmpty ? 'i18n.dart' : '$outputDir/$fileName.dart'; - FileWriter().write(contents: formattedString, path: path); + FileWriter().write(contents: codeGenerator.fileContents, path: path); + + // format the contents according to dart defaults + Process.run('dart', ['format', path]); FlappyLogger.logProgress('Localizations successfully generated!'); } diff --git a/pubspec.yaml b/pubspec.yaml index 6c4d933..8d5c9a0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,12 +6,11 @@ repository: https://github.com/smartnsoft/FlappyTranslator issue_tracker: https://github.com/smartnsoft/FlappyTranslator/issues environment: - sdk: '>=3.0.0 <4.0.0' + sdk: ^3.0.0 dependencies: arb_generator: 0.0.4 yaml: ^3.1.0 - dart_style: ^2.3.0 excel: ^3.0.0 # currently cannot update to ^4.0.0 due to https://github.com/justkawal/excel/pull/368/ dev_dependencies: diff --git a/test/services/code_generation/code_generator_test.dart b/test/services/code_generation/code_generator_test.dart index 12f1f85..a4034ba 100644 --- a/test/services/code_generation/code_generator_test.dart +++ b/test/services/code_generation/code_generator_test.dart @@ -2,7 +2,7 @@ import 'package:flappy_translator/src/services/code_generation/code_generator.da import 'package:test/test.dart'; void main() { - test('formattedString', () { + test('fileContents', () { final codeGenerator = CodeGenerator( className: 'I18n', dependOnContext: false, @@ -10,7 +10,7 @@ void main() { ); expect( - codeGenerator.formattedString, + codeGenerator.fileContents, ''' // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: public_member_api_docs, prefer_single_quotes, avoid_escaping_inner_quotes, prefer_const_constructors, sort_constructors_first, always_specify_types, non_constant_identifier_names @@ -34,8 +34,7 @@ class I18n { static late Locale _locale; - static String _getText(String key) => - _localizedValues[key] ?? '** \$key not found'; + static String _getText(String key) => _localizedValues[key] ?? '** \$key not found'; static Locale get currentLocale => _locale; @@ -63,7 +62,7 @@ class I18nDelegate extends LocalizationsDelegate { ); }); - test('formattedString', () { + test('fileContents', () { final codeGenerator = CodeGenerator( className: 'I18n', dependOnContext: false, @@ -72,7 +71,7 @@ class I18nDelegate extends LocalizationsDelegate { codeGenerator.setSupportedLanguages(['en_US', 'de']); expect( - codeGenerator.formattedString, + codeGenerator.fileContents.normalized, ''' // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: public_member_api_docs, prefer_single_quotes, avoid_escaping_inner_quotes, prefer_const_constructors, sort_constructors_first, always_specify_types, non_constant_identifier_names @@ -96,8 +95,7 @@ class I18n { static late Locale _locale; - static String _getText(String key) => - _localizedValues[key] ?? '** \$key not found'; + static String _getText(String key) => _localizedValues[key] ?? '** \$key not found'; static Locale get currentLocale => _locale; @@ -127,7 +125,8 @@ class I18nDelegate extends LocalizationsDelegate { @override bool shouldReload(I18nDelegate old) => false; } -''', +''' + .normalized, ); }); @@ -146,7 +145,7 @@ class I18nDelegate extends LocalizationsDelegate { codeGenerator.finalize(); expect( - codeGenerator.formattedString, + codeGenerator.fileContents.normalized, ''' // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: public_member_api_docs, prefer_single_quotes, avoid_escaping_inner_quotes, prefer_const_constructors, sort_constructors_first, always_specify_types, non_constant_identifier_names @@ -217,7 +216,8 @@ class I18nDelegate extends LocalizationsDelegate { @override bool shouldReload(I18nDelegate old) => false; } -''', +''' + .normalized, ); }); @@ -235,7 +235,7 @@ class I18nDelegate extends LocalizationsDelegate { codeGenerator.finalize(); expect( - codeGenerator.formattedString, + codeGenerator.fileContents.normalized, ''' // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: public_member_api_docs, prefer_single_quotes, avoid_escaping_inner_quotes, prefer_const_constructors, sort_constructors_first, always_specify_types, non_constant_identifier_names @@ -298,7 +298,8 @@ class I18nDelegate extends LocalizationsDelegate { @override bool shouldReload(I18nDelegate old) => false; } -''', +''' + .normalized, ); }); @@ -314,7 +315,7 @@ class I18nDelegate extends LocalizationsDelegate { codeGenerator.finalize(); expect( - codeGenerator.formattedString, + codeGenerator.fileContents.normalized, ''' // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: public_member_api_docs, prefer_single_quotes, avoid_escaping_inner_quotes, prefer_const_constructors, sort_constructors_first, always_specify_types, non_constant_identifier_names @@ -377,7 +378,8 @@ class I18nDelegate extends LocalizationsDelegate { @override bool shouldReload(I18nDelegate old) => false; } -''', +''' + .normalized, ); }); @@ -393,7 +395,7 @@ class I18nDelegate extends LocalizationsDelegate { codeGenerator.finalize(); expect( - codeGenerator.formattedString, + codeGenerator.fileContents.normalized, ''' // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: public_member_api_docs, prefer_single_quotes, avoid_escaping_inner_quotes, prefer_const_constructors, sort_constructors_first, always_specify_types, non_constant_identifier_names @@ -456,7 +458,8 @@ class I18nDelegate extends LocalizationsDelegate { @override bool shouldReload(I18nDelegate old) => false; } -''', +''' + .normalized, ); }); @@ -471,7 +474,7 @@ class I18nDelegate extends LocalizationsDelegate { codeGenerator.finalize(); expect( - codeGenerator.formattedString, + codeGenerator.fileContents.normalized, ''' // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: public_member_api_docs, prefer_single_quotes, avoid_escaping_inner_quotes, prefer_const_constructors, sort_constructors_first, always_specify_types, non_constant_identifier_names @@ -547,7 +550,8 @@ class I18nDelegate extends LocalizationsDelegate { @override bool shouldReload(I18nDelegate old) => false; } -''', +''' + .normalized, ); }); @@ -562,7 +566,7 @@ class I18nDelegate extends LocalizationsDelegate { codeGenerator.finalize(); expect( - codeGenerator.formattedString, + codeGenerator.fileContents.normalized, ''' // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: public_member_api_docs, prefer_single_quotes, avoid_escaping_inner_quotes, prefer_const_constructors, sort_constructors_first, always_specify_types, non_constant_identifier_names @@ -637,7 +641,12 @@ class I18nDelegate extends LocalizationsDelegate { @override bool shouldReload(I18nDelegate old) => false; } -''', +''' + .normalized, ); }); } + +extension on String { + String get normalized => replaceAll(RegExp(r'\s+'), ''); +}