Aucune description

settings_page.dart 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:flutter/material.dart';
  2. import 'package:userstory2translate/classes/language.dart';
  3. import 'package:userstory2translate/localization/language_constants.dart';
  4. import 'package:userstory2translate/main.dart';
  5. class SettingsPage extends StatefulWidget {
  6. SettingsPage({Key key}) : super(key: key);
  7. @override
  8. _SettingsPageState createState() => _SettingsPageState();
  9. }
  10. class _SettingsPageState extends State<SettingsPage> {
  11. void _changeLanguage(Language language) async {
  12. Locale _locale = await setLocale(language.languageCode);
  13. MyApp.setLocale(context, _locale);
  14. }
  15. @override
  16. Widget build(BuildContext context) {
  17. return Scaffold(
  18. appBar: AppBar(
  19. title: Text(getTranslated(context, 'settings')),
  20. ),
  21. body: Container(
  22. child: Center(
  23. child: DropdownButton<Language>(
  24. iconSize: 30,
  25. hint: Text(getTranslated(context, 'change_language')),
  26. onChanged: (Language language) {
  27. _changeLanguage(language);
  28. },
  29. items: Language.languageList()
  30. .map<DropdownMenuItem<Language>>(
  31. (e) => DropdownMenuItem<Language>(
  32. value: e,
  33. child: Row(
  34. mainAxisAlignment: MainAxisAlignment.spaceAround,
  35. children: <Widget>[
  36. Text(
  37. e.flag,
  38. style: TextStyle(fontSize: 30),
  39. ),
  40. Text(e.name)
  41. ],
  42. ),
  43. ),
  44. )
  45. .toList(),
  46. )),
  47. ),
  48. );
  49. }
  50. }