-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
464 lines (432 loc) · 13.9 KB
/
main.dart
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
import 'dart:async';
import 'dart:math';
import 'dart:ui' as ui show Image;
import 'package:flutter/material.dart';
import 'package:collegesocial/pages/Home.dart';
import 'package:collegesocial/pages/Discover.dart';
import 'package:collegesocial/pages/Polls.dart';
import 'package:collegesocial/pages/Message.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
themeMode: ThemeMode.dark,
title: 'Flutter Demo',
home: AppWithBottomBar(),
);
}
}
class AppWithBottomBar extends StatefulWidget {
@override
_AppWithBottomBarState createState() => _AppWithBottomBarState();
}
class _AppWithBottomBarState extends State<AppWithBottomBar> {
PageStorageBucket _pageStorageBucket;
int selectedPage;
final List<Widget> pages = [
HomePage(
key: PageStorageKey("Home"),
),
DiscoverPage(
key: PageStorageKey("Discover"),
),
PollsPage(
key: PageStorageKey("Polls"),
),
MessagePage(
key: PageStorageKey("Message"),
),
ProfilePage(
key: PageStorageKey("Profile"),
),
];
@override
void initState() {
super.initState();
_pageStorageBucket = PageStorageBucket();
selectedPage = 0;
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF0F0F0D),
body: PageStorage(bucket: _pageStorageBucket, child: pages[selectedPage]),
bottomNavigationBar: Container(
decoration: BoxDecoration(
color: Color(0xFF0F0F0D),
border: Border(
top: BorderSide(
color: Color(0xFF121312),
width: 2.0,
),
),
),
child: BottomNavigationBar(
onTap: (newPage) => setState(() => selectedPage = newPage),
currentIndex: selectedPage,
backgroundColor: Colors.transparent,
type: BottomNavigationBarType.fixed,
elevation: 0.0,
unselectedItemColor: Color(0xFF4E4E4D),
selectedItemColor: Color(0xFFF6BB0A),
selectedFontSize: 12.0,
unselectedFontSize: 12.0,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text("Home"),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text("Discover"),
),
BottomNavigationBarItem(
icon: Icon(Icons.poll),
title: Text("Polls"),
),
BottomNavigationBarItem(
icon: Icon(Icons.mail_outline),
title: Text("Message"),
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
title: Text("Profile"),
),
],
),
),
);
}
}
class ProfilePage extends StatefulWidget {
ProfilePage({Key key}) : super(key: key);
@override
_ProfilePageState createState() => _ProfilePageState();
}
List<String> randomImages = [
'https://via.placeholder.com/150',
'https://via.placeholder.com/150x300',
'https://via.placeholder.com/300x150'
];
class _ProfilePageState extends State<ProfilePage>
with SingleTickerProviderStateMixin {
TabController tabController;
@override
void initState() {
super.initState();
tabController = TabController(length: 4, vsync: this);
}
@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Positioned(
top: 0,
child: Image.network(
"https://specials-images.forbesimg.com/imageserve/5d5c30d095808800097d6380/960x0.jpg",
fit: BoxFit.fitWidth,
height: 300,
color: Colors.black38,
colorBlendMode: BlendMode.darken,
),
),
SafeArea(
minimum: EdgeInsets.only(
left: 15.0,
right: 15.0,
),
child: Row(
children: <Widget>[
Text(
"Home",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w800,
fontSize: 34.0,
),
),
Spacer(),
Material(
clipBehavior: Clip.hardEdge,
color: Colors.transparent,
shape: CircleBorder(
side: BorderSide(
color: Color(0xFFF6AF09),
width: 2.0,
),
),
child: IconButton(
icon: Icon(
Icons.photo_filter,
size: 28.0,
color: Color(0xFFF6AF09),
),
onPressed: () {
print("clicked");
},
),
),
],
),
),
Padding(
padding: EdgeInsets.only(top: 200),
child: Material(
color: Color(0xFF191919),
borderRadius: BorderRadius.only(
topRight: Radius.circular(40.0),
topLeft: Radius.circular(40.0)),
child: ClipRRect(
borderRadius: BorderRadius.only(
topRight: Radius.circular(40.0),
topLeft: Radius.circular(40.0)),
child: Padding(
padding:
const EdgeInsets.only(left: 15.0, right: 15.0, top: 60.0),
child: Column(
children: <Widget>[
Text(
"Jake Muller",
style: TextStyle(
color: Colors.white,
fontSize: 28.0,
fontWeight: FontWeight.w700,
),
),
Padding(
padding: const EdgeInsets.only(top: 10.0, bottom: 20.0),
child: Text(
"Computer Science",
style:
TextStyle(color: Color(0xFF484848), fontSize: 18.0),
),
),
Text(
"Invidunt at clita sadipscing sed consetetur sit. At et dolore sit tempor ea dolor.",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
TabBar(
controller: tabController,
indicatorSize: TabBarIndicatorSize.label,
indicator: RoundedUnderlineTabIndicator(
borderSide:
BorderSide(color: Color(0xFFF6BC0A), width: 4.0),
insets: EdgeInsets.symmetric(horizontal: 8.0),
rounded: true,
),
labelColor: Color(0xFFF6BC0A),
unselectedLabelColor: Color(0xFF434343),
labelStyle: TextStyle(fontSize: 18.0),
unselectedLabelStyle: TextStyle(fontSize: 18.0),
tabs: [
Tab(
text: "Feed",
),
Tab(
text: "Story",
),
Tab(
text: "Videos",
),
Tab(
text: "Liked",
),
],
),
Expanded(
child: TabBarView(
controller: tabController,
children: <Widget>[
FeedTab(),
Container(),
Container(),
Container(),
],
),
),
],
),
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 150.0),
child: Container(
height: 100,
width: 100,
decoration: ShapeDecoration(
shape: CircleBorder(), color: Color(0xFFF6BC0A)),
padding: EdgeInsets.all(4.0),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: CircleBorder(),
image: DecorationImage(
image: NetworkImage(
"https://www.fakepersongenerator.com/Face/female/female1022944243378.jpg"),
fit: BoxFit.cover)),
),
),
),
],
);
}
}
class FeedTab extends StatefulWidget {
@override
_FeedTabState createState() => _FeedTabState();
}
class _FeedTabState extends State<FeedTab> {
@override
Widget build(BuildContext context) {
return StaggeredGridView.countBuilder(
crossAxisCount: 2,
itemBuilder: (context, index) {
return ClickableImage(
url: randomImages[new Random().nextInt(randomImages.length)],
onClick: () {
print("tapped: " + index.toString());
},
);
},
staggeredTileBuilder: (index) {
return StaggeredTile.fit(1);
},
itemCount: 20,
mainAxisSpacing: 15,
crossAxisSpacing: 15,
);
}
}
class ClickableImage extends StatefulWidget {
final String url;
final VoidCallback onClick;
ClickableImage({this.url, this.onClick});
@override
_ClickableImageState createState() => _ClickableImageState();
}
class _ClickableImageState extends State<ClickableImage>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<Color> animation;
@override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: Duration(milliseconds: 200));
animation = ColorTween(
begin: Colors.transparent,
end: Colors.black26,
).animate(_controller)
..addListener(() => setState(() {}));
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTapDown: (_) {
_controller.forward();
},
onTapUp: (_) {
_controller.reverse();
},
onTap: widget.onClick,
onTapCancel: () {
_controller.reverse();
},
child: ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: Image.network(
widget.url,
fit: BoxFit.contain,
color: animation.value,
colorBlendMode: BlendMode.darken,
),
),
);
}
}
class RoundedUnderlineTabIndicator extends Decoration {
/// Create an underline style selected tab indicator.
///
/// The [borderSide] and [insets] arguments must not be null.
const RoundedUnderlineTabIndicator({
this.borderSide = const BorderSide(width: 2.0, color: Colors.white),
this.insets = EdgeInsets.zero,
this.rounded = false,
}) : assert(borderSide != null),
assert(insets != null);
/// The color and weight of the horizontal line drawn below the selected tab.
final BorderSide borderSide;
/// Locates the selected tab's underline relative to the tab's boundary.
///
/// The [TabBar.indicatorSize] property can be used to define the
/// tab indicator's bounds in terms of its (centered) tab widget with
/// [TabIndicatorSize.label], or the entire tab with [TabIndicatorSize.tab].
final EdgeInsetsGeometry insets;
final bool rounded;
@override
Decoration lerpFrom(Decoration a, double t) {
if (a is RoundedUnderlineTabIndicator) {
return RoundedUnderlineTabIndicator(
borderSide: BorderSide.lerp(a.borderSide, borderSide, t),
insets: EdgeInsetsGeometry.lerp(a.insets, insets, t),
rounded: rounded);
}
return super.lerpFrom(a, t);
}
@override
Decoration lerpTo(Decoration b, double t) {
if (b is RoundedUnderlineTabIndicator) {
return RoundedUnderlineTabIndicator(
borderSide: BorderSide.lerp(borderSide, b.borderSide, t),
insets: EdgeInsetsGeometry.lerp(insets, b.insets, t),
rounded: b.rounded);
}
return super.lerpTo(b, t);
}
@override
_UnderlinePainter createBoxPainter([VoidCallback onChanged]) {
return _UnderlinePainter(this, onChanged);
}
}
class _UnderlinePainter extends BoxPainter {
_UnderlinePainter(this.decoration, VoidCallback onChanged)
: assert(decoration != null),
super(onChanged);
final RoundedUnderlineTabIndicator decoration;
BorderSide get borderSide => decoration.borderSide;
EdgeInsetsGeometry get insets => decoration.insets;
bool get isRounded => decoration.rounded;
Rect _indicatorRectFor(Rect rect, TextDirection textDirection) {
assert(rect != null);
assert(textDirection != null);
final Rect indicator = insets.resolve(textDirection).deflateRect(rect);
return Rect.fromLTWH(
indicator.left,
indicator.bottom - borderSide.width,
indicator.width,
borderSide.width,
);
}
@override
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
assert(configuration != null);
assert(configuration.size != null);
assert(isRounded != null);
final Rect rect = offset & configuration.size;
final TextDirection textDirection = configuration.textDirection;
final Rect indicator =
_indicatorRectFor(rect, textDirection).deflate(borderSide.width / 2.0);
final Paint paint = borderSide.toPaint()
..strokeCap = isRounded ? StrokeCap.round : StrokeCap.square;
canvas.drawLine(indicator.bottomLeft, indicator.bottomRight, paint);
}
}