@@ -4,6 +4,10 @@ import 'package:log_file_client/components/tank_thumbnail.dart';
44import 'package:log_file_client/utils/http_client.dart' ;
55import 'package:skeletonizer/skeletonizer.dart' ;
66
7+ enum TankInfoType { pH, temp }
8+
9+ enum TankInfoMode { current, range }
10+
711class TankCard extends StatelessWidget {
812 const TankCard ({
913 required this .log,
@@ -29,25 +33,26 @@ class TankCard extends StatelessWidget {
2933 onTap: onTap,
3034 child: LayoutBuilder (
3135 builder: (BuildContext context, BoxConstraints constraints) {
32- // Decide sizes of internal components based on card width
3336 final double cardWidth = constraints.maxWidth * 0.93 ;
34- final double titleFontSize = cardWidth * 0.05 ;
35- final double descriptionFontSize = cardWidth * 0.04 ;
37+ final double titleFontSize = 20 ;
38+ final double tankInfoFontSize = 16 ;
39+ final double tankInfoHeaderFontSize = 14 ;
3640
3741 // ignore: discarded_futures
3842 final Future <TankSnapshot > tankSnapshot = getTankSnapshot ();
3943
4044 return Container (
41- margin: EdgeInsets .all (cardWidth * 0.075 ),
45+ margin: EdgeInsets .all (30 ),
4246 decoration: _cardBackground (),
4347 child: Column (
48+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
4449 children: [
4550 _graphThumbnailBuilder (tankSnapshot, cardWidth),
4651 _tankName (titleFontSize),
4752 _tankInfoBuilder (
4853 tankSnapshot,
49- cardWidth ,
50- descriptionFontSize ,
54+ tankInfoFontSize ,
55+ tankInfoHeaderFontSize ,
5156 ),
5257 ],
5358 ),
@@ -91,21 +96,12 @@ class TankCard extends StatelessWidget {
9196 );
9297 }
9398
94- Container _graphThumbnail (
99+ Widget _graphThumbnail (
95100 double cardWidth,
96101 AsyncSnapshot <TankSnapshot >? snapshot,
97102 ) {
98- return Container (
99- width: cardWidth,
103+ return SizedBox (
100104 height: cardWidth * 0.6 ,
101- margin: EdgeInsets .only (
102- bottom: cardWidth * 0.05 ,
103- ),
104- decoration: BoxDecoration (
105- borderRadius: BorderRadius .vertical (
106- top: Radius .circular (20 ),
107- ),
108- ),
109105 child: ClipRRect (
110106 borderRadius: BorderRadius .vertical (
111107 top: Radius .circular (20 ),
@@ -139,26 +135,33 @@ class TankCard extends StatelessWidget {
139135
140136 Widget _tankInfoBuilder (
141137 Future <TankSnapshot > tankSnapshot,
142- double cardWidth ,
143- double descriptionFontSize ,
138+ double tankInfoFontSize ,
139+ double tankInfoHeaderFontSize ,
144140 ) {
145141 return FutureBuilder (
146142 future: tankSnapshot,
147143 builder: (context, snapshot) {
148144 if (snapshot.connectionState == ConnectionState .waiting) {
149- return _skeletonLoaderInfo (cardWidth, descriptionFontSize);
145+ return _skeletonLoaderInfo (
146+ tankInfoFontSize,
147+ tankInfoHeaderFontSize,
148+ );
150149 } else if (snapshot.hasError) {
151150 return Center (child: Text ('Error: ${snapshot .error }' ));
152151 } else {
153- return _tankInfo (cardWidth, descriptionFontSize, snapshot);
152+ return _tankInfo (
153+ tankInfoFontSize,
154+ tankInfoHeaderFontSize,
155+ snapshot,
156+ );
154157 }
155158 },
156159 );
157160 }
158161
159162 Skeletonizer _skeletonLoaderInfo (
160- double cardWidth ,
161- double descriptionFontSize ,
163+ double tankInfoFontSize ,
164+ double tankInfoHeaderFontSize ,
162165 ) {
163166 return Skeletonizer (
164167 textBoneBorderRadius: TextBoneBorderRadius (BorderRadius .circular (4 )),
@@ -167,47 +170,107 @@ class TankCard extends StatelessWidget {
167170 highlightColor: Colors .grey[100 ]! ,
168171 duration: Duration (seconds: 2 ),
169172 ),
170- child: _tankInfo (cardWidth, descriptionFontSize , null ),
173+ child: _tankInfo (tankInfoFontSize, tankInfoHeaderFontSize , null ),
171174 );
172175 }
173176
174177 Widget _tankInfo (
175- double cardWidth ,
176- double descriptionFontSize ,
178+ double tankInfoFontSize ,
179+ double tankInfoHeaderFontSize ,
177180 AsyncSnapshot <TankSnapshot >? snapshot,
178181 ) {
179182 return Padding (
180- padding: EdgeInsets .only (top : cardWidth * 0.06 ),
183+ padding: const EdgeInsets .only (bottom : 15 ),
181184 child: Row (
182185 mainAxisAlignment: MainAxisAlignment .spaceEvenly,
183186 children: [
184- _tankInfoLine ('ph' , descriptionFontSize, snapshot),
185- _tankInfoLine ('temp' , descriptionFontSize, snapshot),
187+ _tankInfoBlock (
188+ TankInfoMode .current,
189+ tankInfoFontSize,
190+ tankInfoHeaderFontSize,
191+ snapshot,
192+ ),
193+ _tankInfoBlock (
194+ TankInfoMode .range,
195+ tankInfoFontSize,
196+ tankInfoHeaderFontSize,
197+ snapshot,
198+ ),
186199 ],
187200 ),
188201 );
189202 }
190203
191- Row _tankInfoLine (
192- String type,
193- double descriptionFontSize,
204+ Widget _tankInfoBlock (
205+ TankInfoMode mode,
206+ double tankInfoFontSize,
207+ double tankInfoHeaderFontSize,
194208 AsyncSnapshot <TankSnapshot >? snapshot,
195209 ) {
210+ return Column (
211+ children: [
212+ _tankInfoHeader (mode, tankInfoHeaderFontSize),
213+ _tankInfoLine (TankInfoType .pH, mode, tankInfoFontSize, snapshot),
214+ _tankInfoLine (TankInfoType .temp, mode, tankInfoFontSize, snapshot),
215+ ],
216+ );
217+ }
218+
219+ Widget _tankInfoHeader (TankInfoMode mode, double tankInfoHeaderFontSize) {
220+ return Text (
221+ mode == TankInfoMode .current ? 'Current' : '12hr Range' ,
222+ style: TextStyle (
223+ fontSize: tankInfoHeaderFontSize,
224+ fontWeight: FontWeight .normal,
225+ color: Colors .grey.shade500,
226+ ),
227+ );
228+ }
229+
230+ Widget _tankInfoLine (
231+ TankInfoType type,
232+ TankInfoMode mode,
233+ double tankInfoFontSize,
234+ AsyncSnapshot <TankSnapshot >? snapshot,
235+ ) {
236+ final IconData iconType =
237+ type == TankInfoType .pH ? Icons .water_drop : Icons .thermostat;
238+ final Color iconColor =
239+ type == TankInfoType .pH ? Colors .green : Colors .blue;
240+
241+ String textData = 'mock' ;
242+ if (mode == TankInfoMode .current) {
243+ if (type == TankInfoType .pH) {
244+ textData = 'pH ${snapshot ?.data !.pH ?? 'mock' }' ;
245+ } else {
246+ textData = '${snapshot ?.data !.temperature ?? 'mock' }°C' ;
247+ }
248+ } else if (mode == TankInfoMode .range) {
249+ if (type == TankInfoType .pH) {
250+ final min = snapshot? .data! .minPH ?? 'm.k' ;
251+ final max = snapshot? .data! .maxPH ?? 'm.k' ;
252+ textData = 'pH $min - $max ' ;
253+ } else {
254+ final min = snapshot? .data! .minTemp ?? 'mk' ;
255+ final max = snapshot? .data! .maxTemp ?? 'mk' ;
256+ textData = '$min - $max °C' ;
257+ }
258+ }
259+
196260 return Row (
197261 children: [
198262 Skeleton .keep (
199263 child: Icon (
200- type == 'ph' ? Icons .water_drop : Icons .thermostat ,
201- color: type == 'ph' ? Colors .green : Colors .blue ,
202- size: descriptionFontSize ,
264+ iconType ,
265+ color: iconColor ,
266+ size: tankInfoFontSize ,
203267 ),
204268 ),
269+ SizedBox (width: 5 ),
205270 Text (
206- type == 'ph'
207- ? 'pH ${snapshot ?.data !.pH ?? 'mock' }'
208- : '${snapshot ?.data !.temperature ?? 'mock' }°C' ,
271+ textData,
209272 style: TextStyle (
210- fontSize: descriptionFontSize ,
273+ fontSize: tankInfoFontSize ,
211274 color: const Color (0xFF6D6D6D ),
212275 ),
213276 ),
0 commit comments