From b60ebf66986725f4be0ac6f25518bf225c1c1f0b Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Sun, 11 Apr 2021 20:43:57 +0900 Subject: [PATCH] remove locale name package (-3 MB) --- lib/main.dart | 2 -- lib/utils/constants.dart | 16 +++++----------- lib/widgets/settings/language.dart | 22 +++++++++++++--------- pubspec.lock | 7 ------- pubspec.yaml | 2 +- 5 files changed, 19 insertions(+), 30 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 13fbebc61..85a98d606 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -24,7 +24,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:flutter_localized_locales/flutter_localized_locales.dart'; import 'package:overlay_support/overlay_support.dart'; import 'package:provider/provider.dart'; @@ -107,7 +106,6 @@ class _AvesAppState extends State { locale: settingsLocale, localizationsDelegates: [ ...AppLocalizations.localizationsDelegates, - LocaleNamesLocalizationsDelegate(), ], supportedLocales: AppLocalizations.supportedLocales, ); diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart index e6c3248a8..a4ef8caf7 100644 --- a/lib/utils/constants.dart +++ b/lib/utils/constants.dart @@ -79,10 +79,10 @@ class Constants { sourceUrl: 'https://github.com/FirebaseExtended/flutterfire', ), Dependency( - name: 'Flutter ijkplayer', + name: 'fijkplayer', license: 'MIT', - licenseUrl: 'https://github.com/CaiJingLong/flutter_ijkplayer/blob/master/LICENSE', - sourceUrl: 'https://github.com/CaiJingLong/flutter_ijkplayer', + licenseUrl: 'https://github.com/deckerst/fijkplayer/blob/master/LICENSE', + sourceUrl: 'https://github.com/deckerst/fijkplayer', ), Dependency( name: 'Google API Availability', @@ -231,8 +231,8 @@ class Constants { Dependency( name: 'Expansion Tile Card', license: 'BSD 3-Clause', - licenseUrl: 'https://github.com/Skylled/expansion_tile_card/blob/master/LICENSE', - sourceUrl: 'https://github.com/Skylled/expansion_tile_card', + licenseUrl: 'https://github.com/deckerst/expansion_tile_card/blob/master/LICENSE', + sourceUrl: 'https://github.com/deckerst/expansion_tile_card', ), Dependency( name: 'Flutter Highlight', @@ -240,12 +240,6 @@ class Constants { licenseUrl: 'https://github.com/git-touch/highlight/blob/master/LICENSE', sourceUrl: 'https://github.com/git-touch/highlight', ), - Dependency( - name: 'Flutter Localized Locales', - license: 'MIT', - licenseUrl: 'https://github.com/guidezpl/flutter-localized-locales/blob/master/LICENSE', - sourceUrl: 'https://github.com/guidezpl/flutter-localized-locales', - ), Dependency( name: 'Flutter Map', license: 'BSD 3-Clause', diff --git a/lib/widgets/settings/language.dart b/lib/widgets/settings/language.dart index 33f9daba4..e79f6eaea 100644 --- a/lib/widgets/settings/language.dart +++ b/lib/widgets/settings/language.dart @@ -9,11 +9,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:flutter_localized_locales/flutter_localized_locales.dart'; class LanguageTile extends StatelessWidget { - final Locale _systemLocale = WidgetsBinding.instance.window.locale; - static const _systemLocaleOption = Locale('system'); @override @@ -21,14 +18,13 @@ class LanguageTile extends StatelessWidget { final current = settings.locale; return ListTile( title: Text(context.l10n.settingsLanguage), - subtitle: Text('${current == null ? '${context.l10n.settingsSystemDefault} • ${_getLocaleName(_systemLocale)}' : _getLocaleName(current)}'), + subtitle: Text('${current == null ? context.l10n.settingsSystemDefault : _getLocaleName(current)}'), onTap: () async { final value = await showDialog( context: context, builder: (context) => AvesSelectionDialog( initialValue: settings.locale ?? _systemLocaleOption, options: _getLocaleOptions(context), - optionSubtitleBuilder: (locale) => locale == _systemLocaleOption ? _getLocaleName(_systemLocale) : null, title: context.l10n.settingsLanguage, ), ); @@ -41,12 +37,20 @@ class LanguageTile extends StatelessWidget { ); } - String _getLocaleName(Locale locale) => LocaleNamesLocalizationsDelegate.nativeLocaleNames[locale.toString()]; + String _getLocaleName(Locale locale) { + // the package `flutter_localized_locales` has the answer for all locales + // but it comes with 3 MB of assets + switch (locale.languageCode) { + case 'en': + return 'English'; + case 'ko': + return '한국어'; + } + return locale.toString(); + } LinkedHashMap _getLocaleOptions(BuildContext context) { - final supportedLocales = List.from(AppLocalizations.supportedLocales); - supportedLocales.removeWhere((locale) => locale == _systemLocale); - final displayLocales = supportedLocales.map((locale) => MapEntry(locale, _getLocaleName(locale))).toList()..sort((a, b) => compareAsciiUpperCase(a.value, b.value)); + final displayLocales = AppLocalizations.supportedLocales.map((locale) => MapEntry(locale, _getLocaleName(locale))).toList()..sort((a, b) => compareAsciiUpperCase(a.value, b.value)); return LinkedHashMap.of({ _systemLocaleOption: context.l10n.settingsSystemDefault, diff --git a/pubspec.lock b/pubspec.lock index 4bbc4f28d..57079ea67 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -321,13 +321,6 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_localized_locales: - dependency: "direct main" - description: - name: flutter_localized_locales - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" flutter_map: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 75836504f..47817cd4f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,7 +42,6 @@ dependencies: firebase_analytics: firebase_crashlytics: flutter_highlight: - flutter_localized_locales: flutter_map: flutter_markdown: flutter_staggered_animations: @@ -108,6 +107,7 @@ flutter: # - /android/app/src/main/res/values-{language}/strings.xml # - /android/app/src/debug/res/values-{language}/strings.xml (optional) # - /android/app/src/profile/res/values-{language}/strings.xml (optional) +# - edit locale name resolution for language setting # generate `AppLocalizations` # % flutter gen-l10n