|
4 | 4 |
|
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/const/color_const.dart'; |
| 10 | +import 'feed_const.dart'; |
7 | 11 |
|
8 | 12 | class FeedPageEleven extends StatefulWidget {
|
9 | 13 | @override
|
10 | 14 | _FeedState createState() => _FeedState();
|
11 | 15 | }
|
12 | 16 |
|
13 |
| -class _FeedState extends State<FeedPageEleven> { |
| 17 | +class _FeedState extends State<FeedPageEleven> |
| 18 | + with SingleTickerProviderStateMixin { |
| 19 | + TabController tabController; |
| 20 | + var curTab = 0; |
| 21 | + |
| 22 | + void initState() { |
| 23 | + super.initState(); |
| 24 | + tabController = TabController(length: 3, vsync: this); |
| 25 | + tabController.addListener(() { |
| 26 | + setState(() { |
| 27 | + curTab = tabController.index; |
| 28 | + }); |
| 29 | + }); |
| 30 | + } |
| 31 | + |
| 32 | + Widget _textBack(content, {size = TEXT_SMALL_2_SIZE, isBold = false}) => Text( |
| 33 | + content, |
| 34 | + style: TextStyle( |
| 35 | + fontSize: SizeUtil.getAxisBoth(size), |
| 36 | + fontWeight: isBold ? FontWeight.w700 : null), |
| 37 | + ); |
| 38 | + |
| 39 | + Widget _listItemContent() => Positioned( |
| 40 | + bottom: 0.1, |
| 41 | + left: SizeUtil.getAxisX(136.0), |
| 42 | + child: Container( |
| 43 | + decoration: BoxDecoration( |
| 44 | + borderRadius: BorderRadius.circular( |
| 45 | + SizeUtil.getAxisBoth(22.0), |
| 46 | + ), |
| 47 | + gradient: LinearGradient(colors: [RED_LIGHT, RED]), |
| 48 | + ), |
| 49 | + height: SizeUtil.getAxisY(182.0), |
| 50 | + width: SizeUtil.getAxisY(528.0), |
| 51 | + child: Stack( |
| 52 | + children: <Widget>[ |
| 53 | + Positioned( |
| 54 | + top: SizeUtil.getAxisY(27.0), |
| 55 | + left: SizeUtil.getAxisX(87.0), |
| 56 | + child: _textBack("Blanche Garcia", |
| 57 | + size: TEXT_SMALL_3_SIZE, isBold: true), |
| 58 | + ), |
| 59 | + Positioned( |
| 60 | + top: SizeUtil.getAxisY(66.0), |
| 61 | + left: SizeUtil.getAxisX(87.0), |
| 62 | + child: |
| 63 | + _textBack("Netherlands Antilles", size: TEXT_NORMAL_SIZE), |
| 64 | + ), |
| 65 | + Positioned( |
| 66 | + top: SizeUtil.getAxisY(27.0), |
| 67 | + right: SizeUtil.getAxisX(33.0), |
| 68 | + child: _textBack("31 Dec"), |
| 69 | + ), |
| 70 | + Positioned( |
| 71 | + bottom: SizeUtil.getAxisY(30.0), |
| 72 | + left: SizeUtil.getAxisX(90.0), |
| 73 | + child: Container( |
| 74 | + alignment: AlignmentDirectional.centerStart, |
| 75 | + child: Row( |
| 76 | + mainAxisAlignment: MainAxisAlignment.start, |
| 77 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 78 | + children: <Widget>[ |
| 79 | + Icon( |
| 80 | + Icons.favorite_border, |
| 81 | + color: TEXT_BLACK, |
| 82 | + size: SizeUtil.getAxisBoth(30.0), |
| 83 | + ), |
| 84 | + SizedBox( |
| 85 | + width: SizeUtil.getAxisX(16.0), |
| 86 | + ), |
| 87 | + _textBack("72"), |
| 88 | + SizedBox( |
| 89 | + width: SizeUtil.getAxisX(45.0), |
| 90 | + ), |
| 91 | + Icon( |
| 92 | + Icons.chat, |
| 93 | + color: TEXT_BLACK, |
| 94 | + size: SizeUtil.getAxisBoth(30.0), |
| 95 | + ), |
| 96 | + SizedBox( |
| 97 | + width: SizeUtil.getAxisX(16.0), |
| 98 | + ), |
| 99 | + _textBack("44"), |
| 100 | + ], |
| 101 | + ), |
| 102 | + ), |
| 103 | + ), |
| 104 | + ], |
| 105 | + ), |
| 106 | + ), |
| 107 | + ); |
| 108 | + |
| 109 | + Widget _listItem(index) => Container( |
| 110 | + alignment: AlignmentDirectional.topStart, |
| 111 | + constraints: BoxConstraints.expand(height: SizeUtil.getAxisY(850.0)), |
| 112 | + child: Stack( |
| 113 | + children: <Widget>[ |
| 114 | + Container( |
| 115 | + alignment: AlignmentDirectional.topStart, |
| 116 | + margin: EdgeInsets.only( |
| 117 | + top: SizeUtil.getAxisY(45.0), |
| 118 | + bottom: SizeUtil.getAxisY(84.0), |
| 119 | + left: SizeUtil.getAxisX(30.0), |
| 120 | + right: SizeUtil.getAxisX(30.0), |
| 121 | + ), |
| 122 | + child: Image.asset( |
| 123 | + index % 2 == 0 |
| 124 | + ? FeedImage.feed11_city1 |
| 125 | + : FeedImage.feed11_city2, |
| 126 | + fit: BoxFit.cover, |
| 127 | + ), |
| 128 | + ), |
| 129 | + _listItemContent(), |
| 130 | + Positioned( |
| 131 | + width: SizeUtil.getAxisBoth(100.0), |
| 132 | + height: SizeUtil.getAxisBoth(100.0), |
| 133 | + bottom: SizeUtil.getAxisY(41.0), |
| 134 | + left: SizeUtil.getAxisX(81.0), |
| 135 | + child: Image.asset(FeedImage.feed11_header), |
| 136 | + ), |
| 137 | + ], |
| 138 | + ), |
| 139 | + ); |
| 140 | + |
| 141 | + Widget _listContainer() => Container( |
| 142 | + child: ListView.builder( |
| 143 | + itemBuilder: (context, index) { |
| 144 | + return _listItem(index); |
| 145 | + }, |
| 146 | + itemCount: 4, |
| 147 | + padding: EdgeInsets.only(top: 0.1), |
| 148 | + ), |
| 149 | + ); |
| 150 | + |
| 151 | + Widget _tabTitleItem(title, isCurrent) => Container( |
| 152 | + width: SizeUtil.getAxisX(220.0), |
| 153 | + height: SizeUtil.getAxisY(154.0), |
| 154 | + alignment: AlignmentDirectional.center, |
| 155 | + decoration: BoxDecoration( |
| 156 | + gradient: LinearGradient( |
| 157 | + colors: isCurrent |
| 158 | + ? [RED_LIGHT, RED] |
| 159 | + : [Color(0x44FFFFFF), Color(0x44FFFFFF)]), |
| 160 | + borderRadius: BorderRadius.circular( |
| 161 | + SizeUtil.getAxisX(22.0), |
| 162 | + ), |
| 163 | + boxShadow: isCurrent |
| 164 | + ? [BoxShadow(color: DARK_COLOR, offset: Offset(0.0, 2.0))] |
| 165 | + : null), |
| 166 | + child: Text( |
| 167 | + title, |
| 168 | + style: TextStyle( |
| 169 | + color: TEXT_BLACK, |
| 170 | + fontSize: SizeUtil.getAxisBoth(TEXT_SMALL_2_SIZE), |
| 171 | + ), |
| 172 | + ), |
| 173 | + ); |
| 174 | + |
| 175 | + Widget _tabView(context) { |
| 176 | + return DefaultTabController( |
| 177 | + length: 3, |
| 178 | + child: Column( |
| 179 | + children: <Widget>[ |
| 180 | + Container( |
| 181 | + constraints: |
| 182 | + BoxConstraints.expand(height: SizeUtil.getAxisY(154.0)), |
| 183 | + child: TabBar( |
| 184 | + controller: tabController, |
| 185 | + tabs: [ |
| 186 | + _tabTitleItem("Products", curTab == 0), |
| 187 | + _tabTitleItem("Recent", curTab == 1), |
| 188 | + _tabTitleItem("News", curTab == 2), |
| 189 | + ], |
| 190 | + isScrollable: false, |
| 191 | + indicatorWeight: 0.0001, |
| 192 | + ), |
| 193 | + ), |
| 194 | + Expanded( |
| 195 | + child: TabBarView( |
| 196 | + children: [ |
| 197 | + _listContainer(), |
| 198 | + _listContainer(), |
| 199 | + _listContainer(), |
| 200 | + ], |
| 201 | + controller: tabController, |
| 202 | + ), |
| 203 | + ) |
| 204 | + ], |
| 205 | + )); |
| 206 | + } |
| 207 | + |
14 | 208 | @override
|
15 | 209 | Widget build(BuildContext context) {
|
16 | 210 | return Scaffold(
|
17 |
| - appBar: AppBar( |
18 |
| - title: Text("Feed Eleven"), |
| 211 | + body: Container( |
| 212 | + decoration: |
| 213 | + BoxDecoration(gradient: LinearGradient(colors: [YELLOW, GREEN])), |
| 214 | + child: Column( |
| 215 | + children: <Widget>[ |
| 216 | + TopTitleBar(), |
| 217 | + SizedBox( |
| 218 | + height: SizeUtil.getAxisY(43.0), |
| 219 | + ), |
| 220 | + Expanded( |
| 221 | + child: _tabView(context), |
| 222 | + ), |
| 223 | + ], |
| 224 | + ), |
19 | 225 | ),
|
20 |
| - body: Text("Feed page Eleven"), |
21 | 226 | );
|
22 | 227 | }
|
| 228 | + |
| 229 | + @override |
| 230 | + void dispose() { |
| 231 | + tabController.dispose(); |
| 232 | + super.dispose(); |
| 233 | + } |
23 | 234 | }
|
0 commit comments