|
4 | 4 | /// Email: niebin312@gmail.com
|
5 | 5 | ///
|
6 | 6 | import "package:flutter/material.dart";
|
| 7 | +import 'top_title.dart'; |
| 8 | +import 'package:flutter_ui_nice/util/SizeUtil.dart'; |
| 9 | +import 'package:flutter_ui_nice/util/GradientUtil.dart'; |
| 10 | +import 'feed_const.dart'; |
| 11 | +import 'package:flutter_ui_nice/const/color_const.dart'; |
| 12 | + |
| 13 | +const posts = [ |
| 14 | + { |
| 15 | + "header": FeedImage.feed13_header1, |
| 16 | + "name": "Katherine Farmer", |
| 17 | + "time": "1 hour ago", |
| 18 | + "desc": "Decorate For Less With Art Posters", |
| 19 | + "like": "123", |
| 20 | + "chat": "67", |
| 21 | + "share": "12", |
| 22 | + "images": [ |
| 23 | + FeedImage.feed13_pic1, |
| 24 | + FeedImage.feed13_pic2, |
| 25 | + FeedImage.feed13_pic3, |
| 26 | + FeedImage.feed13_pic4, |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + "header": FeedImage.feed13_header2, |
| 31 | + "name": "Tyler Guerrero", |
| 32 | + "time": "2 hour ago", |
| 33 | + "desc": "", |
| 34 | + "like": "123", |
| 35 | + "chat": "67", |
| 36 | + "share": "12", |
| 37 | + "images": [ |
| 38 | + FeedImage.feed13_pic1, |
| 39 | + FeedImage.feed13_pic2, |
| 40 | + FeedImage.feed13_pic3, |
| 41 | + FeedImage.feed13_pic4, |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "header": FeedImage.feed13_header3, |
| 46 | + "name": "Hettie Nguyen", |
| 47 | + "time": "3 hour ago", |
| 48 | + "desc": "Decorate For Less With Art Posters", |
| 49 | + "like": "123", |
| 50 | + "chat": "67", |
| 51 | + "share": "12", |
| 52 | + "images": [ |
| 53 | + FeedImage.feed13_pic1, |
| 54 | + FeedImage.feed13_pic2, |
| 55 | + FeedImage.feed13_pic3, |
| 56 | + FeedImage.feed13_pic4, |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "header": FeedImage.feed13_header1, |
| 61 | + "name": "Katherine Farmer", |
| 62 | + "time": "4 hour ago", |
| 63 | + "desc": "", |
| 64 | + "like": "123", |
| 65 | + "chat": "67", |
| 66 | + "share": "12", |
| 67 | + "images": [ |
| 68 | + FeedImage.feed13_pic1, |
| 69 | + FeedImage.feed13_pic2, |
| 70 | + FeedImage.feed13_pic3, |
| 71 | + FeedImage.feed13_pic4, |
| 72 | + ] |
| 73 | + } |
| 74 | +]; |
7 | 75 |
|
8 | 76 | class FeedPageThirteen extends StatefulWidget {
|
9 | 77 | @override
|
10 | 78 | _FeedState createState() => _FeedState();
|
11 | 79 | }
|
12 | 80 |
|
13 | 81 | class _FeedState extends State<FeedPageThirteen> {
|
| 82 | + Widget _textBack(content, |
| 83 | + {color = TEXT_BLACK_LIGHT, |
| 84 | + size = TEXT_SMALL_2_SIZE, |
| 85 | + isBold = false}) => |
| 86 | + Text( |
| 87 | + content, |
| 88 | + style: TextStyle( |
| 89 | + color: color, |
| 90 | + fontSize: SizeUtil.getAxisBoth(size), |
| 91 | + fontWeight: isBold ? FontWeight.w700 : null), |
| 92 | + ); |
| 93 | + |
| 94 | + Widget _itemHeader(item) => Container( |
| 95 | + child: Row( |
| 96 | + mainAxisAlignment: MainAxisAlignment.start, |
| 97 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 98 | + children: <Widget>[ |
| 99 | + Image.asset( |
| 100 | + item["header"], |
| 101 | + height: SizeUtil.getAxisBoth(84.0), |
| 102 | + width: SizeUtil.getAxisBoth(84.0), |
| 103 | + ), |
| 104 | + SizedBox( |
| 105 | + width: SizeUtil.getAxisX(51.0), |
| 106 | + ), |
| 107 | + Column( |
| 108 | + mainAxisAlignment: MainAxisAlignment.start, |
| 109 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 110 | + children: <Widget>[ |
| 111 | + _textBack(item["name"], size: TEXT_SMALL_3_SIZE, isBold: true), |
| 112 | + SizedBox( |
| 113 | + height: SizeUtil.getAxisY(13.0), |
| 114 | + ), |
| 115 | + _textBack(item["time"], size: TEXT_NORMAL_SIZE), |
| 116 | + ], |
| 117 | + ) |
| 118 | + ], |
| 119 | + ), |
| 120 | + ); |
| 121 | + |
| 122 | +// |
| 123 | + Widget _itemAction(item) => Row( |
| 124 | + mainAxisAlignment: MainAxisAlignment.start, |
| 125 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 126 | + children: <Widget>[ |
| 127 | + _actionChild(Icons.favorite_border, item["like"]), |
| 128 | + SizedBox(width: SizeUtil.getAxisX(75.0)), |
| 129 | + _actionChild(Icons.chat, item["chat"]), |
| 130 | + SizedBox(width: SizeUtil.getAxisX(75.0)), |
| 131 | + _actionChild(Icons.share, item["share"]), |
| 132 | + ], |
| 133 | + ); |
| 134 | + |
| 135 | + Widget _actionChild(icon, value) => Row( |
| 136 | + children: <Widget>[ |
| 137 | + Icon( |
| 138 | + icon, |
| 139 | + color: TEXT_BLACK_LIGHT, |
| 140 | + size: SizeUtil.getAxisBoth(30.0), |
| 141 | + ), |
| 142 | + SizedBox(width: SizeUtil.getAxisX(20.0)), |
| 143 | + _textBack(value), |
| 144 | + ], |
| 145 | + ); |
| 146 | + |
| 147 | + Widget _backCard(isEmpty) => Container( |
| 148 | + decoration: BoxDecoration( |
| 149 | + gradient: !isEmpty ? GradientUtil.red() : GradientUtil.blue(), |
| 150 | + borderRadius: BorderRadius.circular( |
| 151 | + SizeUtil.getAxisBoth(22.0), |
| 152 | + ), |
| 153 | + boxShadow: [ |
| 154 | + BoxShadow(color: Color(0x11000000), offset: Offset(0.1, 4.0)) |
| 155 | + ]), |
| 156 | + margin: EdgeInsets.only( |
| 157 | + left: SizeUtil.getAxisX(80.0), right: SizeUtil.getAxisX(40.0)), |
| 158 | + ); |
| 159 | + |
| 160 | + Widget _itemText(item) => Container( |
| 161 | + child: _textBack(item["desc"], size: TEXT_SMALL_3_SIZE), |
| 162 | + ); |
| 163 | + |
| 164 | + Widget _itemImages(item) => Container( |
| 165 | + alignment: AlignmentDirectional.center, |
| 166 | + constraints: BoxConstraints.expand(height: SizeUtil.getAxisY(170.0)), |
| 167 | + child: ListView.builder( |
| 168 | + itemBuilder: (context, index) { |
| 169 | + var img = item["images"][index]; |
| 170 | + return Container( |
| 171 | + margin: EdgeInsets.only( |
| 172 | + left: SizeUtil.getAxisX(20.0), |
| 173 | + right: SizeUtil.getAxisX(20.0), |
| 174 | + ), |
| 175 | + child: Image.asset( |
| 176 | + img, |
| 177 | + width: SizeUtil.getAxisBoth(170.0), |
| 178 | + height: SizeUtil.getAxisBoth(170.0), |
| 179 | + ), |
| 180 | + ); |
| 181 | + }, |
| 182 | + itemCount: item["images"].length, |
| 183 | + scrollDirection: Axis.horizontal, |
| 184 | + ), |
| 185 | + ); |
| 186 | + |
| 187 | + Widget _listItem(item) => Container( |
| 188 | + constraints: BoxConstraints.expand( |
| 189 | + height: SizeUtil.getAxisY( |
| 190 | + item["desc"].toString().isNotEmpty ? 350.0 : 469.0), |
| 191 | + ), |
| 192 | + margin: EdgeInsets.only(top: SizeUtil.getAxisY(40.0)), |
| 193 | + child: Stack( |
| 194 | + children: <Widget>[ |
| 195 | + _backCard(item["desc"].toString().isEmpty), |
| 196 | + Positioned( |
| 197 | + left: SizeUtil.getAxisX(25.0), |
| 198 | + top: SizeUtil.getAxisY(46.0), |
| 199 | + child: _itemHeader(item), |
| 200 | + ), |
| 201 | + Positioned( |
| 202 | + left: SizeUtil.getAxisX(162.0), |
| 203 | + bottom: SizeUtil.getAxisY(45.0), |
| 204 | + child: _itemAction(item), |
| 205 | + ), |
| 206 | + item["desc"].toString().isEmpty |
| 207 | + ? Container( |
| 208 | + margin: EdgeInsets.only(top: SizeUtil.getAxisY(20.0)), |
| 209 | + alignment: AlignmentDirectional.center, |
| 210 | + child: _itemImages(item), |
| 211 | + ) |
| 212 | + : Positioned( |
| 213 | + top: SizeUtil.getAxisY(156.0), |
| 214 | + left: SizeUtil.getAxisX(160.0), |
| 215 | + height: SizeUtil.getAxisY(70.0), |
| 216 | + child: _itemText(item), |
| 217 | + ), |
| 218 | + ], |
| 219 | + ), |
| 220 | + ); |
| 221 | + |
| 222 | + Widget _body() => ListView.builder( |
| 223 | + itemBuilder: (context, index) { |
| 224 | + var item = posts[index % posts.length]; |
| 225 | + return _listItem(item); |
| 226 | + }, |
| 227 | + itemCount: posts.length, |
| 228 | + padding: EdgeInsets.only(top: 0.1), |
| 229 | + ); |
| 230 | + |
14 | 231 | @override
|
15 | 232 | Widget build(BuildContext context) {
|
16 | 233 | return Scaffold(
|
17 |
| - appBar: AppBar( |
18 |
| - title: Text("Feed Thirteen"), |
| 234 | + body: Container( |
| 235 | + decoration: BoxDecoration(gradient: GradientUtil.yellowGreen()), |
| 236 | + child: Column( |
| 237 | + children: <Widget>[ |
| 238 | + TopTitleBar( |
| 239 | + rightImage: FeedImage.feed_add, |
| 240 | + ), |
| 241 | + Expanded( |
| 242 | + child: _body(), |
| 243 | + ) |
| 244 | + ], |
| 245 | + ), |
19 | 246 | ),
|
20 |
| - body: Text("Feed page Thirteen"), |
21 | 247 | );
|
22 | 248 | }
|
23 | 249 | }
|
0 commit comments