|
| 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 | + 'name': AppLocalizations.$t('common_mine_1.environment'), |
| 21 | + 'icon': 57539, // import_export |
| 22 | + 'index': 1, |
| 23 | + }, |
| 24 | + { |
| 25 | + 'name': AppLocalizations.$t('common_mine_1.compProgress'), |
| 26 | + 'icon': 57709, // low_priority |
| 27 | + 'index': 2 |
| 28 | + } |
| 29 | + ]; |
| 30 | + } |
| 31 | + |
| 32 | + actionsEvent(int index) { |
| 33 | + print('index $index'); |
| 34 | + switch (index) { |
| 35 | + case 0: |
| 36 | + this.openLanguageSelectMenu(); |
| 37 | + break; |
| 38 | + case 1: |
| 39 | + this.openEnvSelectMenu(); |
| 40 | + break; |
| 41 | + case 2: |
| 42 | + FluroRouter.router.navigateTo( |
| 43 | + context, |
| 44 | + '/webview?url=${Uri.encodeComponent(widget.model.config.state.env.githubWeb)}&title=${Uri.encodeComponent(AppLocalizations.$t('common.compProgress'))}', |
| 45 | + ); |
| 46 | + break; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + void pop([message]) { |
| 51 | + Navigator.pop(context); |
| 52 | + if (message != null) { |
| 53 | + Scaffold.of(context).showSnackBar(new SnackBar( |
| 54 | + content: new Text(message), |
| 55 | + )); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * 国际化 |
| 61 | + */ |
| 62 | + void openLanguageSelectMenu() async { |
| 63 | + await showModalBottomSheet( |
| 64 | + context: context, |
| 65 | + builder: (BuildContext bc) { |
| 66 | + return Container( |
| 67 | + child: Wrap( |
| 68 | + children: <Widget>[ |
| 69 | + ListTile( |
| 70 | + leading: Icon(Icons.label_outline), |
| 71 | + title: Text( |
| 72 | + AppLocalizations.$t('common_mine_1.cn'), |
| 73 | + ), |
| 74 | + onTap: () { |
| 75 | + AppLocalizations.changeLanguage(Locale('zh')); |
| 76 | + this.pop(AppLocalizations.$t('common_mine_1.success')); |
| 77 | + }, |
| 78 | + ), |
| 79 | + ListTile( |
| 80 | + leading: Icon(Icons.label_outline), |
| 81 | + title: Text(AppLocalizations.$t('common_mine_1.en')), |
| 82 | + onTap: () { |
| 83 | + AppLocalizations.changeLanguage(Locale('en')); |
| 84 | + this.pop(AppLocalizations.$t('common_mine_1.success')); |
| 85 | + }, |
| 86 | + ), |
| 87 | + ], |
| 88 | + ), |
| 89 | + ); |
| 90 | + }, |
| 91 | + ); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * 环境选择 |
| 96 | + */ |
| 97 | + void openEnvSelectMenu() async { |
| 98 | + await showModalBottomSheet( |
| 99 | + context: context, |
| 100 | + builder: (BuildContext bc) { |
| 101 | + return Container( |
| 102 | + child: Wrap( |
| 103 | + children: <Widget>[ |
| 104 | + ListTile( |
| 105 | + leading: Icon(Icons.label_outline), |
| 106 | + title: Text( |
| 107 | + AppLocalizations.$t('mine.loadNetwork'), |
| 108 | + ), |
| 109 | + onTap: () { |
| 110 | + widget.model.dispatch('config', 'setEnv', true); |
| 111 | + this.pop(AppLocalizations.$t('common_mine_1.success')); |
| 112 | + }, |
| 113 | + ), |
| 114 | + ListTile( |
| 115 | + leading: Icon(Icons.label_outline), |
| 116 | + title: Text(AppLocalizations.$t('mine.loadLocal')), |
| 117 | + onTap: () { |
| 118 | + widget.model.dispatch('config', 'setEnv', false); |
| 119 | + this.pop(AppLocalizations.$t('common_mine_1.success')); |
| 120 | + }, |
| 121 | + ), |
| 122 | + ], |
| 123 | + ), |
| 124 | + ); |
| 125 | + }, |
| 126 | + ); |
| 127 | + } |
| 128 | + |
| 129 | + @override |
| 130 | + Widget build(BuildContext context) { |
| 131 | + return SingleChildScrollView( |
| 132 | + child: Column( |
| 133 | + children: <Widget>[ |
| 134 | + Container( |
| 135 | + decoration: BoxDecoration( |
| 136 | + borderRadius: BorderRadius.only( |
| 137 | + bottomLeft: Radius.circular(10), |
| 138 | + bottomRight: Radius.circular(10) |
| 139 | + ), |
| 140 | + color: Colors.red, |
| 141 | + ), |
| 142 | + height: 240, |
| 143 | + child: Stack( |
| 144 | + alignment: const FractionalOffset(0.8, 0.8), |
| 145 | + children: <Widget>[ |
| 146 | + Row( |
| 147 | + children: <Widget>[ |
| 148 | + Image.network( |
| 149 | + 'https://raw.githubusercontent.com/efoxTeam/flutter-ui/master/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png', |
| 150 | + width: 80.0, |
| 151 | + height: 80.0, |
| 152 | + fit: BoxFit.cover, |
| 153 | + ), |
| 154 | + SizedBox( |
| 155 | + width: 10, |
| 156 | + ), |
| 157 | + Text( |
| 158 | + 'Hello Guest', |
| 159 | + style: TextStyle(color: Colors.white), |
| 160 | + ) |
| 161 | + ], |
| 162 | + ) |
| 163 | + ], |
| 164 | + ), |
| 165 | + ), |
| 166 | + ListView.builder( |
| 167 | + shrinkWrap: true, |
| 168 | + itemCount: _getList().length * 2, |
| 169 | + itemBuilder: (context, index) { |
| 170 | + double _index = index / 2; |
| 171 | + if (index % 2 == 0) { |
| 172 | + dynamic item = _getList()[_index.toInt()]; |
| 173 | + return ListTile( |
| 174 | + onTap: () { |
| 175 | + actionsEvent(item['index']); |
| 176 | + }, |
| 177 | + leading: Icon( |
| 178 | + IconData( |
| 179 | + item['icon'], |
| 180 | + fontFamily: 'MaterialIcons', |
| 181 | + matchTextDirection: true, |
| 182 | + ), |
| 183 | + ), |
| 184 | + title: Text(item['name']), |
| 185 | + ); |
| 186 | + } else { |
| 187 | + return Divider( |
| 188 | + color: Color(AppTheme.lineColor), |
| 189 | + ); |
| 190 | + } |
| 191 | + }, |
| 192 | + ), |
| 193 | + ], |
| 194 | + ), |
| 195 | + ); |
| 196 | + } |
| 197 | +} |
| 198 | + |
| 199 | +class Index extends StatefulWidget { |
| 200 | + final dynamic model; |
| 201 | + |
| 202 | + Index({Key key, this.model}) : super(key: key); |
| 203 | + |
| 204 | + @override |
| 205 | + _IndexState createState() => _IndexState(); |
| 206 | +} |
0 commit comments