remove locale name package (-3 MB)
This commit is contained in:
parent
40e9439252
commit
b60ebf6698
5 changed files with 19 additions and 30 deletions
|
@ -24,7 +24,6 @@ import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.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:overlay_support/overlay_support.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
@ -107,7 +106,6 @@ class _AvesAppState extends State<AvesApp> {
|
||||||
locale: settingsLocale,
|
locale: settingsLocale,
|
||||||
localizationsDelegates: [
|
localizationsDelegates: [
|
||||||
...AppLocalizations.localizationsDelegates,
|
...AppLocalizations.localizationsDelegates,
|
||||||
LocaleNamesLocalizationsDelegate(),
|
|
||||||
],
|
],
|
||||||
supportedLocales: AppLocalizations.supportedLocales,
|
supportedLocales: AppLocalizations.supportedLocales,
|
||||||
);
|
);
|
||||||
|
|
|
@ -79,10 +79,10 @@ class Constants {
|
||||||
sourceUrl: 'https://github.com/FirebaseExtended/flutterfire',
|
sourceUrl: 'https://github.com/FirebaseExtended/flutterfire',
|
||||||
),
|
),
|
||||||
Dependency(
|
Dependency(
|
||||||
name: 'Flutter ijkplayer',
|
name: 'fijkplayer',
|
||||||
license: 'MIT',
|
license: 'MIT',
|
||||||
licenseUrl: 'https://github.com/CaiJingLong/flutter_ijkplayer/blob/master/LICENSE',
|
licenseUrl: 'https://github.com/deckerst/fijkplayer/blob/master/LICENSE',
|
||||||
sourceUrl: 'https://github.com/CaiJingLong/flutter_ijkplayer',
|
sourceUrl: 'https://github.com/deckerst/fijkplayer',
|
||||||
),
|
),
|
||||||
Dependency(
|
Dependency(
|
||||||
name: 'Google API Availability',
|
name: 'Google API Availability',
|
||||||
|
@ -231,8 +231,8 @@ class Constants {
|
||||||
Dependency(
|
Dependency(
|
||||||
name: 'Expansion Tile Card',
|
name: 'Expansion Tile Card',
|
||||||
license: 'BSD 3-Clause',
|
license: 'BSD 3-Clause',
|
||||||
licenseUrl: 'https://github.com/Skylled/expansion_tile_card/blob/master/LICENSE',
|
licenseUrl: 'https://github.com/deckerst/expansion_tile_card/blob/master/LICENSE',
|
||||||
sourceUrl: 'https://github.com/Skylled/expansion_tile_card',
|
sourceUrl: 'https://github.com/deckerst/expansion_tile_card',
|
||||||
),
|
),
|
||||||
Dependency(
|
Dependency(
|
||||||
name: 'Flutter Highlight',
|
name: 'Flutter Highlight',
|
||||||
|
@ -240,12 +240,6 @@ class Constants {
|
||||||
licenseUrl: 'https://github.com/git-touch/highlight/blob/master/LICENSE',
|
licenseUrl: 'https://github.com/git-touch/highlight/blob/master/LICENSE',
|
||||||
sourceUrl: 'https://github.com/git-touch/highlight',
|
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(
|
Dependency(
|
||||||
name: 'Flutter Map',
|
name: 'Flutter Map',
|
||||||
license: 'BSD 3-Clause',
|
license: 'BSD 3-Clause',
|
||||||
|
|
|
@ -9,11 +9,8 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:flutter_localized_locales/flutter_localized_locales.dart';
|
|
||||||
|
|
||||||
class LanguageTile extends StatelessWidget {
|
class LanguageTile extends StatelessWidget {
|
||||||
final Locale _systemLocale = WidgetsBinding.instance.window.locale;
|
|
||||||
|
|
||||||
static const _systemLocaleOption = Locale('system');
|
static const _systemLocaleOption = Locale('system');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -21,14 +18,13 @@ class LanguageTile extends StatelessWidget {
|
||||||
final current = settings.locale;
|
final current = settings.locale;
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(context.l10n.settingsLanguage),
|
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 {
|
onTap: () async {
|
||||||
final value = await showDialog<Locale>(
|
final value = await showDialog<Locale>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AvesSelectionDialog<Locale>(
|
builder: (context) => AvesSelectionDialog<Locale>(
|
||||||
initialValue: settings.locale ?? _systemLocaleOption,
|
initialValue: settings.locale ?? _systemLocaleOption,
|
||||||
options: _getLocaleOptions(context),
|
options: _getLocaleOptions(context),
|
||||||
optionSubtitleBuilder: (locale) => locale == _systemLocaleOption ? _getLocaleName(_systemLocale) : null,
|
|
||||||
title: context.l10n.settingsLanguage,
|
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<Locale, String> _getLocaleOptions(BuildContext context) {
|
LinkedHashMap<Locale, String> _getLocaleOptions(BuildContext context) {
|
||||||
final supportedLocales = List<Locale>.from(AppLocalizations.supportedLocales);
|
final displayLocales = AppLocalizations.supportedLocales.map((locale) => MapEntry(locale, _getLocaleName(locale))).toList()..sort((a, b) => compareAsciiUpperCase(a.value, b.value));
|
||||||
supportedLocales.removeWhere((locale) => locale == _systemLocale);
|
|
||||||
final displayLocales = supportedLocales.map((locale) => MapEntry(locale, _getLocaleName(locale))).toList()..sort((a, b) => compareAsciiUpperCase(a.value, b.value));
|
|
||||||
|
|
||||||
return LinkedHashMap.of({
|
return LinkedHashMap.of({
|
||||||
_systemLocaleOption: context.l10n.settingsSystemDefault,
|
_systemLocaleOption: context.l10n.settingsSystemDefault,
|
||||||
|
|
|
@ -321,13 +321,6 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
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:
|
flutter_map:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -42,7 +42,6 @@ dependencies:
|
||||||
firebase_analytics:
|
firebase_analytics:
|
||||||
firebase_crashlytics:
|
firebase_crashlytics:
|
||||||
flutter_highlight:
|
flutter_highlight:
|
||||||
flutter_localized_locales:
|
|
||||||
flutter_map:
|
flutter_map:
|
||||||
flutter_markdown:
|
flutter_markdown:
|
||||||
flutter_staggered_animations:
|
flutter_staggered_animations:
|
||||||
|
@ -108,6 +107,7 @@ flutter:
|
||||||
# - /android/app/src/main/res/values-{language}/strings.xml
|
# - /android/app/src/main/res/values-{language}/strings.xml
|
||||||
# - /android/app/src/debug/res/values-{language}/strings.xml (optional)
|
# - /android/app/src/debug/res/values-{language}/strings.xml (optional)
|
||||||
# - /android/app/src/profile/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`
|
# generate `AppLocalizations`
|
||||||
# % flutter gen-l10n
|
# % flutter gen-l10n
|
||||||
|
|
Loading…
Reference in a new issue