mirror of
https://github.com/stonega/tsacdop
synced 2025-02-13 10:00:49 +01:00
Fixed language bug.
This commit is contained in:
parent
10499285df
commit
20505eafcf
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:intl/intl_standalone.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../generated/l10n.dart';
|
||||
@ -27,14 +28,34 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
|
||||
var localeStorage = KeyValueStorage(localeKey);
|
||||
if (systemDefault) {
|
||||
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 {
|
||||
await localeStorage
|
||||
.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
|
||||
@ -58,21 +79,22 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(s.systemDefault),
|
||||
title: Text(
|
||||
s.systemDefault,
|
||||
style: TextStyle(
|
||||
color: Intl.systemLocale.contains(Intl.getCurrentLocale())
|
||||
? context.accentColor
|
||||
: null),
|
||||
),
|
||||
onTap: () =>
|
||||
_setLocale(Locale(Intl.systemLocale), systemDefault: true),
|
||||
contentPadding: const EdgeInsets.only(left: 75, right: 20),
|
||||
trailing: Radio<Locale>(
|
||||
value: Locale(Intl.systemLocale),
|
||||
groupValue: Locale(Intl.getCurrentLocale()),
|
||||
onChanged: (locale) =>
|
||||
_setLocale(locale, systemDefault: true)),
|
||||
contentPadding: const EdgeInsets.only(left: 70, right: 20),
|
||||
),
|
||||
Divider(height: 2),
|
||||
ListTile(
|
||||
title: Text('English'),
|
||||
onTap: () => _setLocale(Locale('en')),
|
||||
contentPadding: const EdgeInsets.only(left: 75, right: 20),
|
||||
contentPadding: const EdgeInsets.only(left: 70, right: 20),
|
||||
trailing: Radio<Locale>(
|
||||
value: Locale('en'),
|
||||
groupValue: Locale(Intl.getCurrentLocale()),
|
||||
@ -81,7 +103,7 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
|
||||
ListTile(
|
||||
title: Text('简体中文'),
|
||||
onTap: () => _setLocale(Locale('zh_Hans')),
|
||||
contentPadding: const EdgeInsets.only(left: 75, right: 20),
|
||||
contentPadding: const EdgeInsets.only(left: 70, right: 20),
|
||||
trailing: Radio<Locale>(
|
||||
value: Locale('zh_Hans'),
|
||||
groupValue: Locale(Intl.getCurrentLocale()),
|
||||
@ -91,7 +113,7 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
|
||||
ListTile(
|
||||
title: Text('Français'),
|
||||
onTap: () => _setLocale(Locale('fr')),
|
||||
contentPadding: const EdgeInsets.only(left: 75, right: 20),
|
||||
contentPadding: const EdgeInsets.only(left: 70, right: 20),
|
||||
trailing: Radio<Locale>(
|
||||
value: Locale('fr'),
|
||||
groupValue: Locale(Intl.getCurrentLocale()),
|
||||
@ -101,7 +123,7 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
|
||||
ListTile(
|
||||
title: Text('Español'),
|
||||
onTap: () => _setLocale(Locale('es')),
|
||||
contentPadding: const EdgeInsets.only(left: 75, right: 20),
|
||||
contentPadding: const EdgeInsets.only(left: 70, right: 20),
|
||||
trailing: Radio<Locale>(
|
||||
value: Locale('es'),
|
||||
groupValue: Locale(Intl.getCurrentLocale()),
|
||||
@ -111,7 +133,7 @@ class _LanguagesSettingState extends State<LanguagesSetting> {
|
||||
ListTile(
|
||||
onTap: () => _launchUrl(
|
||||
'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(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Image(
|
||||
|
Loading…
x
Reference in New Issue
Block a user