|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:efox_flutter/lang/index.dart' show AppLocalizations; |
| 3 | +import 'package:efox_flutter/router/index.dart' show FluroRouter; |
| 4 | +import 'package:efox_flutter/config/theme.dart' show AppTheme; |
| 5 | + |
| 6 | +class _IndexState extends State<Index> { |
| 7 | + @override |
| 8 | + void initState() { |
| 9 | + super.initState(); |
| 10 | + } |
| 11 | + |
| 12 | + List<dynamic> _getList() { |
| 13 | + return [ |
| 14 | + { |
| 15 | + 'name': AppLocalizations.$t('common_mine_1.language'), |
| 16 | + 'icon': 59540, // language |
| 17 | + 'index': 0 |
| 18 | + }, |
| 19 | + ]; |
| 20 | + } |
| 21 | + |
| 22 | + actionsEvent(int index) { |
| 23 | + print('index $index'); |
| 24 | + switch (index) { |
| 25 | + case 0: |
| 26 | + this.openLanguageSelectMenu(); |
| 27 | + break; |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + void pop([message]) { |
| 32 | + Navigator.pop(context); |
| 33 | + if (message != null) { |
| 34 | + Scaffold.of(context).showSnackBar(new SnackBar( |
| 35 | + content: new Text(message), |
| 36 | + )); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * 国际化 |
| 42 | + */ |
| 43 | + void openLanguageSelectMenu() async { |
| 44 | + await showModalBottomSheet( |
| 45 | + context: context, |
| 46 | + builder: (BuildContext bc) { |
| 47 | + return Container( |
| 48 | + child: Wrap( |
| 49 | + children: <Widget>[ |
| 50 | + ListTile( |
| 51 | + //leading: Icon(Icons.label_outline), |
| 52 | + title: Text( |
| 53 | + AppLocalizations.$t('common_mine_1.cn'), |
| 54 | + ), |
| 55 | + onTap: () { |
| 56 | + AppLocalizations.changeLanguage(Locale('zh')); |
| 57 | + this.pop(AppLocalizations.$t('common_mine_1.success')); |
| 58 | + }, |
| 59 | + ), |
| 60 | + ListTile( |
| 61 | + //leading: Icon(Icons.label_outline), |
| 62 | + title: Text(AppLocalizations.$t('common_mine_1.en')), |
| 63 | + onTap: () { |
| 64 | + AppLocalizations.changeLanguage(Locale('en')); |
| 65 | + this.pop(AppLocalizations.$t('common_mine_1.success')); |
| 66 | + }, |
| 67 | + ), |
| 68 | + ], |
| 69 | + ), |
| 70 | + ); |
| 71 | + }, |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + @override |
| 76 | + Widget build(BuildContext context) { |
| 77 | + return Scaffold( |
| 78 | + appBar: AppBar( |
| 79 | + elevation: 0, |
| 80 | + centerTitle: true, |
| 81 | + title: Text(AppLocalizations.$t('nav_title_1'))), |
| 82 | + body: ListView.builder( |
| 83 | + shrinkWrap: true, |
| 84 | + itemCount: _getList().length * 2, |
| 85 | + itemBuilder: (context, index) { |
| 86 | + double _index = index / 2; |
| 87 | + if (index % 2 == 0) { |
| 88 | + dynamic item = _getList()[_index.toInt()]; |
| 89 | + return ListTile( |
| 90 | + onTap: () { |
| 91 | + actionsEvent(item['index']); |
| 92 | + }, |
| 93 | + leading: Icon( |
| 94 | + IconData( |
| 95 | + item['icon'], |
| 96 | + fontFamily: 'MaterialIcons', |
| 97 | + matchTextDirection: true, |
| 98 | + ), |
| 99 | + ), |
| 100 | + title: Text(item['name']), |
| 101 | + ); |
| 102 | + } else { |
| 103 | + return Divider( |
| 104 | + color: Color(AppTheme.lineColor), |
| 105 | + ); |
| 106 | + } |
| 107 | + }, |
| 108 | + ), |
| 109 | + ); |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +class Index extends StatefulWidget { |
| 114 | + final dynamic model; |
| 115 | + |
| 116 | + Index({Key key, this.model}) : super(key: key); |
| 117 | + |
| 118 | + @override |
| 119 | + _IndexState createState() => _IndexState(); |
| 120 | +} |
0 commit comments