|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:efox_flutter/store/models/main_state_model.dart' |
| 3 | + show MainStateModel; |
| 4 | +import 'package:efox_flutter/config/theme.dart' show AppTheme; |
| 5 | +import 'package:efox_flutter/widget/index.dart' as WidgetRoot; |
| 6 | +import 'package:efox_flutter/router/index.dart' show FluroRouter; |
| 7 | +import 'package:efox_flutter/lang/index.dart' show AppLocalizations; |
| 8 | +import 'package:efox_flutter/components/headerComp.dart' as Header; |
| 9 | + |
| 10 | +class Index extends StatefulWidget { |
| 11 | + final MainStateModel model; |
| 12 | + Index({Key key, this.model}) : super(key: key); |
| 13 | + @override |
| 14 | + _IndexState createState() => new _IndexState(); |
| 15 | +} |
| 16 | + |
| 17 | +class _IndexState extends State<Index> |
| 18 | + with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin { |
| 19 | + List _mapList = WidgetRoot.getAllWidgets(); |
| 20 | + int _currentIndex = -1; |
| 21 | + TabController _tabController; |
| 22 | + |
| 23 | + @override |
| 24 | + bool get wantKeepAlive => true; |
| 25 | + |
| 26 | + @override |
| 27 | + initState() { |
| 28 | + super.initState(); |
| 29 | + _tabController = new TabController(vsync: this, length: _mapList.length); |
| 30 | + _tabController.addListener(() { |
| 31 | + if (_currentIndex != _tabController.index) { |
| 32 | + _currentIndex = _tabController.index; |
| 33 | + } |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + @override |
| 38 | + void dispose() { |
| 39 | + _tabController.dispose(); |
| 40 | + super.dispose(); |
| 41 | + } |
| 42 | + |
| 43 | + final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); |
| 44 | + |
| 45 | + Widget build(BuildContext context) { |
| 46 | + return Scaffold( |
| 47 | + key: _scaffoldKey, |
| 48 | + /* appBar: AppBar( |
| 49 | + title: Header.Index( |
| 50 | + AppLocalizations.$t('nav_title_0'), |
| 51 | + ), |
| 52 | + actions: appBarActions(), |
| 53 | + ), */ |
| 54 | + appBar: PreferredSize( |
| 55 | + preferredSize: Size.fromHeight(kToolbarHeight), |
| 56 | + child: Container( |
| 57 | + color: Color(AppTheme.mainColor), |
| 58 | + child: SafeArea( |
| 59 | + child: this._TabBar(), |
| 60 | + ), |
| 61 | + ), |
| 62 | + ), |
| 63 | + body: Column( |
| 64 | + children: <Widget>[ |
| 65 | + //this._TabBar(), |
| 66 | + this._TabView() |
| 67 | + ], |
| 68 | + )); |
| 69 | + } |
| 70 | + |
| 71 | + Widget _TabBar() { |
| 72 | + return TabBar( |
| 73 | + controller: _tabController, |
| 74 | + isScrollable: true, |
| 75 | + tabs: _mapList.map((v) { |
| 76 | + return new Tab( |
| 77 | + text: v.typeName, |
| 78 | + /* icon: Icon( |
| 79 | + IconData( |
| 80 | + v.code, |
| 81 | + fontFamily: 'MaterialIcons', |
| 82 | + matchTextDirection: true, |
| 83 | + ), |
| 84 | + ), */ |
| 85 | + ); |
| 86 | + }).toList()); |
| 87 | + } |
| 88 | + |
| 89 | + Widget _TabView() { |
| 90 | + return Expanded( |
| 91 | + child: new TabBarView( |
| 92 | + controller: _tabController, |
| 93 | + children: List.generate(_mapList.length, (index) { |
| 94 | + return this.Grids(_mapList[index], index); |
| 95 | + })), |
| 96 | + ); |
| 97 | + } |
| 98 | + |
| 99 | + Widget Grids(widgetsItem, index) { |
| 100 | + String nameSpaces = widgetsItem.nameSpaces; |
| 101 | + List _tmpWidgetList = widgetsItem.widgetList; |
| 102 | + |
| 103 | + return Container( |
| 104 | + child: GridView.count( |
| 105 | + childAspectRatio: 1.3, |
| 106 | + padding: EdgeInsets.fromLTRB(4, 0, 4, 0), |
| 107 | + shrinkWrap: true, |
| 108 | + physics: ScrollPhysics(), |
| 109 | + crossAxisCount: 3, |
| 110 | + children: List.generate( |
| 111 | + _tmpWidgetList.length, |
| 112 | + (index) { |
| 113 | + return Container( |
| 114 | + decoration: BoxDecoration( |
| 115 | + border: |
| 116 | + Border.all(color: Color(AppTheme.lineColor), width: 0.5)), |
| 117 | + child: FlatButton( |
| 118 | + color: Color(AppTheme.secondColor), |
| 119 | + splashColor: Color(AppTheme.mainColor), |
| 120 | + child: Column( |
| 121 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 122 | + mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
| 123 | + children: [ |
| 124 | + Icon( |
| 125 | + IconData( |
| 126 | + _tmpWidgetList[index].code, |
| 127 | + fontFamily: 'MaterialIcons', |
| 128 | + matchTextDirection: true, |
| 129 | + ), |
| 130 | + color: Color(AppTheme.mainColor), |
| 131 | + size: 32, |
| 132 | + ), |
| 133 | + Text( |
| 134 | + '${_tmpWidgetList[index].title}', |
| 135 | + //overflow: TextOverflow.ellipsis, |
| 136 | + style: |
| 137 | + TextStyle(fontSize: 14, fontWeight: FontWeight.w300), |
| 138 | + ) |
| 139 | + ], |
| 140 | + ), |
| 141 | + onPressed: () { |
| 142 | + FluroRouter.router.navigateTo( |
| 143 | + context, |
| 144 | + nameSpaces + _tmpWidgetList[index].title, |
| 145 | + ); |
| 146 | + }, |
| 147 | + ), |
| 148 | + ); |
| 149 | + }, |
| 150 | + ), |
| 151 | + ), |
| 152 | + ); |
| 153 | + } |
| 154 | + |
| 155 | + List<Widget> appBarActions() { |
| 156 | + return [ |
| 157 | + PopupMenuButton( |
| 158 | + icon: Icon( |
| 159 | + Icons.more_vert, |
| 160 | + ), |
| 161 | + onSelected: (local) { |
| 162 | + AppLocalizations.changeLanguage(Locale(local)); |
| 163 | + print('local=$local'); |
| 164 | + }, |
| 165 | + itemBuilder: (context) => [ |
| 166 | + PopupMenuItem( |
| 167 | + child: Row( |
| 168 | + children: <Widget>[ |
| 169 | + Text('中文'), |
| 170 | + ], |
| 171 | + ), |
| 172 | + value: 'zh', |
| 173 | + ), |
| 174 | + PopupMenuItem( |
| 175 | + child: Row( |
| 176 | + children: <Widget>[ |
| 177 | + Text('english'), |
| 178 | + ], |
| 179 | + ), |
| 180 | + value: 'en', |
| 181 | + ), |
| 182 | + ], |
| 183 | + ), |
| 184 | + ]; |
| 185 | + } |
| 186 | +} |
0 commit comments