1
0
mirror of https://github.com/stonega/tsacdop synced 2025-02-13 10:00:49 +01:00

Fixed language bug.

This commit is contained in:
stonegate 2020-08-13 17:58:24 +08:00
parent 10499285df
commit 20505eafcf

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:intl/intl_standalone.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import '../generated/l10n.dart'; import '../generated/l10n.dart';
@ -27,14 +28,34 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
var localeStorage = KeyValueStorage(localeKey); var localeStorage = KeyValueStorage(localeKey);
if (systemDefault) { if (systemDefault) {
await localeStorage.saveStringList([]); await localeStorage.saveStringList([]);
await findSystemLocale();
var systemLanCode;
final list = Intl.systemLocale.split('_');
if (list.length == 2) {
systemLanCode = list.first;
} else if (list.length == 3) {
systemLanCode = '${list[0]}_${list[1]}';
} else {
systemLanCode = 'en';
}
await S.load(Locale(systemLanCode));
if (mounted) {
setState(() {});
}
} else { } else {
await localeStorage await localeStorage
.saveStringList([locale.languageCode, locale.countryCode]); .saveStringList([locale.languageCode, locale.countryCode]);
await S.load(locale);
if (mounted) {
setState(() {});
}
} }
await S.load(locale); }
if (mounted) {
setState(() {}); @override
} void initState() {
super.initState();
findSystemLocale();
} }
@override @override
@ -58,21 +79,22 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
child: Column( child: Column(
children: [ children: [
ListTile( ListTile(
title: Text(s.systemDefault), title: Text(
s.systemDefault,
style: TextStyle(
color: Intl.systemLocale.contains(Intl.getCurrentLocale())
? context.accentColor
: null),
),
onTap: () => onTap: () =>
_setLocale(Locale(Intl.systemLocale), systemDefault: true), _setLocale(Locale(Intl.systemLocale), systemDefault: true),
contentPadding: const EdgeInsets.only(left: 75, right: 20), contentPadding: const EdgeInsets.only(left: 70, right: 20),
trailing: Radio<Locale>(
value: Locale(Intl.systemLocale),
groupValue: Locale(Intl.getCurrentLocale()),
onChanged: (locale) =>
_setLocale(locale, systemDefault: true)),
), ),
Divider(height: 2), Divider(height: 2),
ListTile( ListTile(
title: Text('English'), title: Text('English'),
onTap: () => _setLocale(Locale('en')), onTap: () => _setLocale(Locale('en')),
contentPadding: const EdgeInsets.only(left: 75, right: 20), contentPadding: const EdgeInsets.only(left: 70, right: 20),
trailing: Radio<Locale>( trailing: Radio<Locale>(
value: Locale('en'), value: Locale('en'),
groupValue: Locale(Intl.getCurrentLocale()), groupValue: Locale(Intl.getCurrentLocale()),
@ -81,7 +103,7 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
ListTile( ListTile(
title: Text('简体中文'), title: Text('简体中文'),
onTap: () => _setLocale(Locale('zh_Hans')), onTap: () => _setLocale(Locale('zh_Hans')),
contentPadding: const EdgeInsets.only(left: 75, right: 20), contentPadding: const EdgeInsets.only(left: 70, right: 20),
trailing: Radio<Locale>( trailing: Radio<Locale>(
value: Locale('zh_Hans'), value: Locale('zh_Hans'),
groupValue: Locale(Intl.getCurrentLocale()), groupValue: Locale(Intl.getCurrentLocale()),
@ -91,7 +113,7 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
ListTile( ListTile(
title: Text('Français'), title: Text('Français'),
onTap: () => _setLocale(Locale('fr')), onTap: () => _setLocale(Locale('fr')),
contentPadding: const EdgeInsets.only(left: 75, right: 20), contentPadding: const EdgeInsets.only(left: 70, right: 20),
trailing: Radio<Locale>( trailing: Radio<Locale>(
value: Locale('fr'), value: Locale('fr'),
groupValue: Locale(Intl.getCurrentLocale()), groupValue: Locale(Intl.getCurrentLocale()),
@ -101,7 +123,7 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
ListTile( ListTile(
title: Text('Español'), title: Text('Español'),
onTap: () => _setLocale(Locale('es')), onTap: () => _setLocale(Locale('es')),
contentPadding: const EdgeInsets.only(left: 75, right: 20), contentPadding: const EdgeInsets.only(left: 70, right: 20),
trailing: Radio<Locale>( trailing: Radio<Locale>(
value: Locale('es'), value: Locale('es'),
groupValue: Locale(Intl.getCurrentLocale()), groupValue: Locale(Intl.getCurrentLocale()),
@ -111,7 +133,7 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
ListTile( ListTile(
onTap: () => _launchUrl( onTap: () => _launchUrl(
'mailto:<tsacdop.app@gmail.com>?subject=Tsacdop localization project'), 'mailto:<tsacdop.app@gmail.com>?subject=Tsacdop localization project'),
contentPadding: const EdgeInsets.only(left: 75, right: 20), contentPadding: const EdgeInsets.only(left: 70, right: 20),
title: Align( title: Align(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Image( child: Image(