1
-
2
1
/// Created with Android Studio.
3
2
/// User: 三帆
4
3
/// Date: 16/01/2019
5
4
/// Time: 11:16
6
5
7
6
/// target: app首页
8
7
9
-
10
8
import 'package:flutter/material.dart' ;
11
9
import 'package:flutter/rendering.dart' ;
12
10
import 'package:flutter_go/utils/shared_preferences.dart' ;
@@ -22,10 +20,6 @@ import 'package:flutter_go/components/search_input.dart';
22
20
import 'package:flutter_go/model/search_history.dart' ;
23
21
import 'package:flutter_go/resources/widget_name_to_icon.dart' ;
24
22
25
- import './first_page/main_page.dart' ;
26
-
27
-
28
-
29
23
const int ThemeColor = 0xFFC91B3A ;
30
24
31
25
class AppPage extends StatefulWidget {
@@ -40,41 +34,40 @@ class _MyHomePageState extends State<AppPage>
40
34
SpUtil sp;
41
35
WidgetControlModel widgetControl = new WidgetControlModel ();
42
36
SearchHistoryList searchHistoryList;
43
- TabController controller;
44
37
bool isSearch = false ;
45
- String data = '无' ;
46
- String data2ThirdPage = '这是传给ThirdPage的值' ;
47
38
String appBarTitle = tabData[0 ]['text' ];
39
+ List <Widget > list = List ();
40
+ int _currentIndex = 0 ;
48
41
static List tabData = [
49
- {'text' : '业界动态' , 'icon' : new Icon (Icons .language)},
50
- {'text' : 'WIDGET' , 'icon' : new Icon (Icons .extension )},
51
- {'text' : '组件收藏' , 'icon' : new Icon (Icons .favorite)},
52
- {'text' : '关于手册' , 'icon' : new Icon (Icons .import_contacts)}
42
+ {'text' : '业界动态' , 'icon' : Icon (Icons .language)},
43
+ {'text' : 'WIDGET' , 'icon' : Icon (Icons .extension )},
44
+ {'text' : '组件收藏' , 'icon' : Icon (Icons .favorite)},
45
+ {'text' : '关于手册' , 'icon' : Icon (Icons .import_contacts)}
53
46
];
54
47
55
- List <Widget > myTabs = [];
48
+ List <BottomNavigationBarItem > myTabs = [];
56
49
57
50
@override
58
51
void initState () {
59
52
super .initState ();
60
-
61
53
initSearchHistory ();
62
- controller = new TabController (
63
- initialIndex: 0 , vsync: this , length: 4 ); // 这里的length 决定有多少个底导 submenus
64
54
for (int i = 0 ; i < tabData.length; i++ ) {
65
- myTabs.add (new Tab (text: tabData[i]['text' ], icon: tabData[i]['icon' ]));
55
+ myTabs.add (BottomNavigationBarItem (
56
+ icon: tabData[i]['icon' ],
57
+ title: Text (
58
+ tabData[i]['text' ],
59
+ ),
60
+ ));
66
61
}
67
- controller.addListener (() {
68
- if (controller.indexIsChanging) {
69
- _onTabChange ();
70
- }
71
- });
72
- Application .controller = controller;
62
+ list
63
+ ..add (FirstPage ())
64
+ ..add (WidgetPage (Provider .db))
65
+ ..add (CollectionPage ())
66
+ ..add (FourthPage ());
73
67
}
74
68
75
69
@override
76
70
void dispose () {
77
- controller.dispose ();
78
71
super .dispose ();
79
72
}
80
73
@@ -106,7 +99,6 @@ class _MyHomePageState extends State<AppPage>
106
99
return new SearchInput ((value) async {
107
100
if (value != '' ) {
108
101
List <WidgetPoint > list = await widgetControl.search (value);
109
-
110
102
return list
111
103
.map ((item) => new MaterialSearchResult <String >(
112
104
value: item.name,
@@ -123,63 +115,31 @@ class _MyHomePageState extends State<AppPage>
123
115
}, (value) {}, () {});
124
116
}
125
117
126
- renderAppBar (BuildContext context,Widget widget) {
127
- print ('renderAppBar=====>>>>>>${controller .index }' );
128
- if (controller.index == 0 ) {
129
- return null ;
130
- }
131
- return AppBar (title: buildSearchInput (context));
132
- }
133
118
134
119
@override
135
120
Widget build (BuildContext context) {
136
- var db = Provider .db;
137
-
138
121
return new Scaffold (
139
- appBar: renderAppBar (context,widget),
140
- body: new TabBarView (controller: controller, children: < Widget > [
141
- //new FirstPage(),
142
- MainPage (),
143
- WidgetPage (db),
144
- CollectionPage (),
145
- FourthPage ()
146
- ]),
147
- bottomNavigationBar: Material (
148
- color: const Color (0xFFF0EEEF ), //底部导航栏主题颜色
149
- child: SafeArea (
150
- child: Container (
151
- height: 65.0 ,
152
- decoration: BoxDecoration (
153
- color: const Color (0xFFF0F0F0 ),
154
- boxShadow: < BoxShadow > [
155
- BoxShadow (
156
- color: const Color (0xFFd0d0d0 ),
157
- blurRadius: 3.0 ,
158
- spreadRadius: 2.0 ,
159
- offset: Offset (- 1.0 , - 1.0 ),
160
- ),
161
- ],
162
- ),
163
- child: TabBar (
164
- controller: controller,
165
- indicatorColor: Theme .of (context).primaryColor,
166
- //tab标签的下划线颜色
167
- // labelColor: const Color(0xFF000000),
168
- indicatorWeight: 3.0 ,
169
- labelColor: Theme .of (context).primaryColor,
170
- unselectedLabelColor: const Color (0xFF8E8E8E ),
171
- tabs: myTabs),
172
- ),
173
- ),
122
+ appBar: new AppBar (title: buildSearchInput (context)),
123
+ body: list[_currentIndex],
124
+ bottomNavigationBar: BottomNavigationBar (
125
+ items: myTabs,
126
+ //高亮 被点击高亮
127
+ currentIndex: _currentIndex,
128
+ //修改 页面
129
+ onTap: _ItemTapped ,
130
+ //shifting :按钮点击移动效果
131
+ //fixed:固定
132
+ type: BottomNavigationBarType .fixed,
133
+
134
+ fixedColor: Color (0xFFC91B3A ),
174
135
),
175
136
);
176
137
}
177
138
178
- void _onTabChange () {
179
- if (this .mounted) {
180
- this .setState (() {
181
- appBarTitle = tabData[controller.index]['text' ];
182
- });
183
- }
139
+ void _ItemTapped (int index) {
140
+ setState (() {
141
+ _currentIndex = index;
142
+ appBarTitle = tabData[index]['text' ];
143
+ });
184
144
}
185
145
}
0 commit comments