2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/common/language.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/settings/settings_store.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
|
|
|
|
|
|
|
class ChangeLanguage extends BasePage {
|
2020-01-08 12:26:34 +00:00
|
|
|
@override
|
|
|
|
String get title => S.current.settings_change_language;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) {
|
|
|
|
final settingsStore = Provider.of<SettingsStore>(context);
|
|
|
|
final currentLanguage = Provider.of<Language>(context);
|
|
|
|
|
2020-01-10 15:46:43 +00:00
|
|
|
final currentColor = Theme.of(context).selectedRowColor;
|
|
|
|
final notCurrentColor = Theme.of(context).accentTextTheme.subhead.backgroundColor;
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
|
|
|
|
child: ListView.builder(
|
2020-02-26 17:18:58 +00:00
|
|
|
itemCount: languages.values.length,
|
2020-01-04 19:31:52 +00:00
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
final isCurrent = settingsStore.languageCode == null
|
|
|
|
? false
|
2020-02-26 17:18:58 +00:00
|
|
|
: languages.keys.elementAt(index) ==
|
2020-01-04 19:31:52 +00:00
|
|
|
settingsStore.languageCode;
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
|
2020-01-10 15:46:43 +00:00
|
|
|
color: isCurrent ? currentColor : notCurrentColor,
|
2020-01-04 19:31:52 +00:00
|
|
|
child: ListTile(
|
|
|
|
title: Text(
|
2020-02-26 17:18:58 +00:00
|
|
|
languages.values.elementAt(index),
|
2020-01-04 19:31:52 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16.0,
|
|
|
|
color: Theme.of(context).primaryTextTheme.title.color),
|
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
if (!isCurrent) {
|
2020-01-08 12:26:34 +00:00
|
|
|
await showDialog<void>(
|
2020-01-04 19:31:52 +00:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text(
|
|
|
|
S.of(context).change_language,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
content: Text(
|
|
|
|
S.of(context).change_language_to(
|
2020-02-26 17:18:58 +00:00
|
|
|
languages.values.elementAt(index)),
|
2020-01-04 19:31:52 +00:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
FlatButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
child: Text(S.of(context).cancel)),
|
|
|
|
FlatButton(
|
|
|
|
onPressed: () {
|
|
|
|
settingsStore.saveLanguageCode(
|
|
|
|
languageCode:
|
2020-02-26 17:18:58 +00:00
|
|
|
languages.keys.elementAt(index));
|
2020-01-04 19:31:52 +00:00
|
|
|
currentLanguage.setCurrentLanguage(
|
2020-02-26 17:18:58 +00:00
|
|
|
languages.keys.elementAt(index));
|
2020-01-04 19:31:52 +00:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Text(S.of(context).change)),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|