|
19 | 19 |
|
20 | 20 | import 'package:boxbox/Screens/Racing/circuit.dart'; |
21 | 21 | import 'package:boxbox/Screens/Racing/circuit_details.dart'; |
| 22 | +import 'package:boxbox/api/formulae.dart'; |
22 | 23 | import 'package:boxbox/helpers/buttons.dart'; |
| 24 | +import 'package:boxbox/helpers/loading_indicator_util.dart'; |
23 | 25 | import 'package:boxbox/l10n/app_localizations.dart'; |
| 26 | +import 'package:cached_network_image/cached_network_image.dart'; |
24 | 27 | import 'package:flutter/material.dart'; |
25 | 28 | import 'package:hive_flutter/hive_flutter.dart'; |
26 | 29 |
|
@@ -145,4 +148,65 @@ class CircuitUIProvider { |
145 | 148 | return Container(); |
146 | 149 | } |
147 | 150 | } |
| 151 | + |
| 152 | + Widget getRaceImage(String meetingId, Map details, BuildContext context) { |
| 153 | + String championship = Hive.box('settings') |
| 154 | + .get('championship', defaultValue: 'Formula 1') as String; |
| 155 | + if (championship == 'Formula 1') { |
| 156 | + return CachedNetworkImage( |
| 157 | + errorWidget: (context, url, error) => const Icon(Icons.error_outlined), |
| 158 | + fadeOutDuration: const Duration(milliseconds: 300), |
| 159 | + fadeInDuration: const Duration(milliseconds: 300), |
| 160 | + fit: BoxFit.cover, |
| 161 | + imageUrl: details['raceImage']['url'], |
| 162 | + placeholder: (context, url) => const LoadingIndicatorUtil(), |
| 163 | + colorBlendMode: BlendMode.darken, |
| 164 | + height: MediaQuery.of(context).size.width > 780 |
| 165 | + ? MediaQuery.of(context).size.height |
| 166 | + : MediaQuery.of(context).size.height * (4 / 9), |
| 167 | + ); |
| 168 | + } else if (championship == 'Formula E') { |
| 169 | + return FutureBuilder( |
| 170 | + future: FormulaE().getCircuitImageUrl(meetingId), |
| 171 | + builder: (context, snapshot) => snapshot.hasError |
| 172 | + ? Container() |
| 173 | + : snapshot.hasData |
| 174 | + ? CachedNetworkImage( |
| 175 | + errorWidget: (context, url, error) => |
| 176 | + const Icon(Icons.error_outlined), |
| 177 | + fadeOutDuration: const Duration(milliseconds: 300), |
| 178 | + fadeInDuration: const Duration(milliseconds: 300), |
| 179 | + fit: BoxFit.cover, |
| 180 | + imageUrl: snapshot.data!, |
| 181 | + placeholder: (context, url) => Container(), |
| 182 | + colorBlendMode: BlendMode.darken, |
| 183 | + height: MediaQuery.of(context).size.width > 780 |
| 184 | + ? MediaQuery.of(context).size.height |
| 185 | + : MediaQuery.of(context).size.height * (4 / 9), |
| 186 | + ) |
| 187 | + : Container(), |
| 188 | + ); |
| 189 | + } else { |
| 190 | + return Container(); |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + Widget getRaceFlag(Map details, BuildContext context) { |
| 195 | + String championship = Hive.box('settings') |
| 196 | + .get('championship', defaultValue: 'Formula 1') as String; |
| 197 | + if (championship == 'Formula 1') { |
| 198 | + return CachedNetworkImage( |
| 199 | + errorWidget: (context, url, error) => SizedBox(width: 53), |
| 200 | + fadeOutDuration: const Duration(milliseconds: 300), |
| 201 | + fadeInDuration: const Duration(milliseconds: 300), |
| 202 | + placeholder: (context, url) => SizedBox(width: 53), |
| 203 | + fit: BoxFit.cover, |
| 204 | + imageUrl: details['raceCountryFlag']['url'], |
| 205 | + height: MediaQuery.of(context).size.width > 780 ? 60 : 30, |
| 206 | + width: MediaQuery.of(context).size.width > 780 ? 106 : 53, |
| 207 | + ); |
| 208 | + } else { |
| 209 | + return Container(); |
| 210 | + } |
| 211 | + } |
148 | 212 | } |
0 commit comments