-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathhome.dart
More file actions
240 lines (219 loc) · 7.09 KB
/
home.dart
File metadata and controls
240 lines (219 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import 'package:everything_flutter/constants/app_colors.dart';
import 'package:everything_flutter/constants/strings.dart';
import 'package:everything_flutter/constants/test_data.dart';
import 'package:everything_flutter/constants/theme_data.dart';
import 'package:everything_flutter/helpers/screen_util.dart';
import 'package:everything_flutter/model/news.dart';
import 'package:everything_flutter/ui/widgets/menu_card.dart';
import 'package:everything_flutter/ui/widgets/news_item.dart';
import 'package:flutter/material.dart';
import 'package:functional_widget_annotation/functional_widget_annotation.dart';
import 'package:intl/intl.dart';
import 'package:snaplist/snaplist.dart';
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); // ADD THIS LINE
@override
void initState() {
// model.dispose(FetchNewsData());
super.initState();
}
@override
Widget build(BuildContext context) {
ScreenUtil()..init(context);
return Scaffold(
key: _scaffoldKey,
appBar: _buildAppBar(),
body: _buildBody(),
drawer: _buildDrawer(),
);
}
@widget
Widget _buildBody() => SafeArea(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
_timelineTitle,
_buildMenuCards(),
_buildNewsFeedBar(),
_buildNewsStand(news)
],
),
),
);
@widget
Widget _buildNewsFeedBar() => Padding(
padding: ScreenUtil.getPaddingLTRB(4, 2, 4, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Your News Feed",
style: TextStyles.miniTitle,
),
GestureDetector(
onTap : () {
_scaffoldKey.currentState.openDrawer(); // CHANGE THIS LINE
},
child: Icon(
Icons.more_vert,
size: ScreenUtil.getFullScreen(12),
),
),
],
),
);
}
List<News> news = [newsItem, newsItemTwo,newsItemThree];
final _timelineTitle = Text(
"Your Timeline",
style: TextStyles.title,
);
@widget
Container _buildMenuCards() => Container(
height: ScreenUtil.getHeight(35),
width: double.infinity,
child: SnapList(
builder: (context, index, data) => MenuCard(
height: ScreenUtil.getHeight(40),
width: ScreenUtil.getWidth(65),
margin: ScreenUtil.getPaddingLTRB(2, 1, 0, 0),
borderRadius: ScreenUtil.getBorderRadiusCircular(12),
imageAsset: imageAssets[index],
color: AppColors.pastelColors[index],
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
padding: ScreenUtil.getPaddingAll(10),
decoration: BoxDecoration(
borderRadius: ScreenUtil.getBorderRadiusCircular(12),
color: Colors.white70,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Text(
menuCardTitles[index],
style: TextStyle(
fontSize: ScreenUtil.getTextSize(13),
fontWeight: FontWeight.w800,
color: AppColors.titleColors[index],
),
),
GestureDetector(
onTap: () =>
Navigator.pushNamed(context, menuCardTitles[index]),
child: Container(
padding: ScreenUtil.getPaddingAll(8),
decoration: BoxDecoration(
borderRadius: ScreenUtil.getBorderRadiusCircular(12),
color: AppColors.buttonColors[index],
boxShadow: [
new BoxShadow(
color: AppColors.buttonColors[index],
blurRadius: 8.0,
),
]),
child: Icon(Icons.arrow_forward_ios,
size: ScreenUtil.getTextSize(13),
color: Colors.white),
),
),
],
),
),
),
),
count: 4,
sizeProvider: (index, data) =>
Size(ScreenUtil.getWidth(65), ScreenUtil.getHeight(35)),
separatorProvider: (index, data) =>
Size(ScreenUtil.getWidth(1), ScreenUtil.getHeight(5)),
),
);
@widget
Drawer _buildDrawer() => Drawer(
child: ListView(
children: <Widget>[
DrawerHeader(
child: Text('Custom Header'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
leading: Icon(Icons.photo),
title: Text('First layout'),
),
ListTile(
title: Text('Communicate'),
//without leading =)
),
ListTile(
leading: Icon(Icons.share),
title: Text('Share layout'),
)
],
),
);
@widget
AppBar _buildAppBar() => AppBar(
title: _appBarTitle,
iconTheme: IconThemeData(color: Colors.black),
elevation: 0,
brightness: Brightness.light,
// or use Brightness.dark
backgroundColor: Colors.grey[50],
);
final _appBarTitle = Align(
alignment: Alignment.centerRight,
child: Text(
"${DateFormat("MMM d, yyyy").format(DateTime.now())}",
style: TextStyles.subtitle,
),
);
@widget
Widget _buildNewsStand(List<News> newsList) {
List<Widget> _columnItems = [];
for (var news in newsList) {
_columnItems.add(NewsItem(news));
// _columnItems.add(Divider());
}
return Column(children: _columnItems);
}
Widget _getInformationMessage(String message) {
return Center(
child: Text(
message,
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.w900, color: Colors.grey[500]),
),
);
}
// StreamBuilder(
// stream: model.homeState,
// builder: (context, snapshot) {
// if (snapshot.hasError) {
// return _getInformationMessage(snapshot.error.toString());
// }
//
// var homeState = snapshot.data;
//
// if (!snapshot.hasData || homeState is BusyHomeState) {
// return Center(child: CircularProgressIndicator());
// }
//
// if (homeState is NewsFetchedHomeState) {
// if (!homeState.hasData) {
// return _getInformationMessage(
// 'No data found! Please try again!');
// }
// }
//
// return _buildNewsStand(homeState.data);
// },
// )