Skip to content

Commit faecf13

Browse files
committed
fix(results): now working!
1 parent ff8029f commit faecf13

File tree

4 files changed

+117
-43
lines changed

4 files changed

+117
-43
lines changed

lib/api/services/formula_series.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import 'package:boxbox/classes/race.dart';
2525
import 'package:boxbox/classes/team.dart';
2626
import 'package:boxbox/helpers/constants.dart';
2727
import 'package:boxbox/providers/circuit/format.dart';
28+
import 'package:boxbox/providers/results/format.dart';
2829
import 'package:hive_flutter/hive_flutter.dart';
2930
import 'package:http/http.dart' as http;
3031
import 'package:intl/intl.dart';
@@ -538,9 +539,10 @@ class FormulaSeries {
538539
}
539540

540541
Future<List<DriverResult>> getSessionResults(
541-
String meetingId,
542-
int sessionIndex,
543-
) async {
542+
String meetingId, {
543+
String? sessionIndex,
544+
String? sessionName,
545+
}) async {
544546
String championship = Hive.box('settings')
545547
.get('championship', defaultValue: 'Formula 1') as String;
546548
String championshipId = Constants().FORMULA_SERIES[championship];
@@ -592,8 +594,17 @@ class FormulaSeries {
592594
}
593595

594596
List sessionResults = formatedResponse['SessionResults'];
597+
if (sessionIndex == null) {
598+
sessionIndex = ResultsFormatProvider()
599+
.getSessionIndexForFormulaSeries(
600+
sessionResults,
601+
sessionName!,
602+
)
603+
.toString();
604+
}
605+
595606
return formatResults(
596-
sessionResults[sessionIndex]['Results'],
607+
sessionResults[int.parse(sessionIndex)]['Results'],
597608
);
598609
}
599610
}

lib/l10n/app_localizations.dart

Lines changed: 83 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@ import 'app_localizations_zh.dart';
8383
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
8484
/// property.
8585
abstract class AppLocalizations {
86-
AppLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
86+
AppLocalizations(String locale)
87+
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
8788

8889
final String localeName;
8990

9091
static AppLocalizations? of(BuildContext context) {
9192
return Localizations.of<AppLocalizations>(context, AppLocalizations);
9293
}
9394

94-
static const LocalizationsDelegate<AppLocalizations> delegate = _AppLocalizationsDelegate();
95+
static const LocalizationsDelegate<AppLocalizations> delegate =
96+
_AppLocalizationsDelegate();
9597

9698
/// A list of this localizations delegate along with the default localizations
9799
/// delegates.
@@ -103,7 +105,8 @@ abstract class AppLocalizations {
103105
/// Additional delegates can be added by appending to this list in
104106
/// MaterialApp. This list does not have to be used at all if a custom list
105107
/// of delegates is preferred or required.
106-
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
108+
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
109+
<LocalizationsDelegate<dynamic>>[
107110
delegate,
108111
GlobalMaterialLocalizations.delegate,
109112
GlobalCupertinoLocalizations.delegate,
@@ -1392,7 +1395,8 @@ abstract class AppLocalizations {
13921395
String get yes;
13931396
}
13941397

1395-
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
1398+
class _AppLocalizationsDelegate
1399+
extends LocalizationsDelegate<AppLocalizations> {
13961400
const _AppLocalizationsDelegate();
13971401

13981402
@override
@@ -1401,46 +1405,90 @@ class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations>
14011405
}
14021406

14031407
@override
1404-
bool isSupported(Locale locale) => <String>['ar', 'bn', 'de', 'el', 'en', 'es', 'fi', 'fr', 'hi', 'hu', 'id', 'it', 'ko', 'ml', 'nb', 'nl', 'pa', 'pl', 'pt', 'sw', 'ta', 'tr', 'zh'].contains(locale.languageCode);
1408+
bool isSupported(Locale locale) => <String>[
1409+
'ar',
1410+
'bn',
1411+
'de',
1412+
'el',
1413+
'en',
1414+
'es',
1415+
'fi',
1416+
'fr',
1417+
'hi',
1418+
'hu',
1419+
'id',
1420+
'it',
1421+
'ko',
1422+
'ml',
1423+
'nb',
1424+
'nl',
1425+
'pa',
1426+
'pl',
1427+
'pt',
1428+
'sw',
1429+
'ta',
1430+
'tr',
1431+
'zh'
1432+
].contains(locale.languageCode);
14051433

14061434
@override
14071435
bool shouldReload(_AppLocalizationsDelegate old) => false;
14081436
}
14091437

14101438
AppLocalizations lookupAppLocalizations(Locale locale) {
1411-
1412-
14131439
// Lookup logic when only language code is specified.
14141440
switch (locale.languageCode) {
1415-
case 'ar': return AppLocalizationsAr();
1416-
case 'bn': return AppLocalizationsBn();
1417-
case 'de': return AppLocalizationsDe();
1418-
case 'el': return AppLocalizationsEl();
1419-
case 'en': return AppLocalizationsEn();
1420-
case 'es': return AppLocalizationsEs();
1421-
case 'fi': return AppLocalizationsFi();
1422-
case 'fr': return AppLocalizationsFr();
1423-
case 'hi': return AppLocalizationsHi();
1424-
case 'hu': return AppLocalizationsHu();
1425-
case 'id': return AppLocalizationsId();
1426-
case 'it': return AppLocalizationsIt();
1427-
case 'ko': return AppLocalizationsKo();
1428-
case 'ml': return AppLocalizationsMl();
1429-
case 'nb': return AppLocalizationsNb();
1430-
case 'nl': return AppLocalizationsNl();
1431-
case 'pa': return AppLocalizationsPa();
1432-
case 'pl': return AppLocalizationsPl();
1433-
case 'pt': return AppLocalizationsPt();
1434-
case 'sw': return AppLocalizationsSw();
1435-
case 'ta': return AppLocalizationsTa();
1436-
case 'tr': return AppLocalizationsTr();
1437-
case 'zh': return AppLocalizationsZh();
1441+
case 'ar':
1442+
return AppLocalizationsAr();
1443+
case 'bn':
1444+
return AppLocalizationsBn();
1445+
case 'de':
1446+
return AppLocalizationsDe();
1447+
case 'el':
1448+
return AppLocalizationsEl();
1449+
case 'en':
1450+
return AppLocalizationsEn();
1451+
case 'es':
1452+
return AppLocalizationsEs();
1453+
case 'fi':
1454+
return AppLocalizationsFi();
1455+
case 'fr':
1456+
return AppLocalizationsFr();
1457+
case 'hi':
1458+
return AppLocalizationsHi();
1459+
case 'hu':
1460+
return AppLocalizationsHu();
1461+
case 'id':
1462+
return AppLocalizationsId();
1463+
case 'it':
1464+
return AppLocalizationsIt();
1465+
case 'ko':
1466+
return AppLocalizationsKo();
1467+
case 'ml':
1468+
return AppLocalizationsMl();
1469+
case 'nb':
1470+
return AppLocalizationsNb();
1471+
case 'nl':
1472+
return AppLocalizationsNl();
1473+
case 'pa':
1474+
return AppLocalizationsPa();
1475+
case 'pl':
1476+
return AppLocalizationsPl();
1477+
case 'pt':
1478+
return AppLocalizationsPt();
1479+
case 'sw':
1480+
return AppLocalizationsSw();
1481+
case 'ta':
1482+
return AppLocalizationsTa();
1483+
case 'tr':
1484+
return AppLocalizationsTr();
1485+
case 'zh':
1486+
return AppLocalizationsZh();
14381487
}
14391488

14401489
throw FlutterError(
1441-
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
1442-
'an issue with the localizations generation tool. Please file an issue '
1443-
'on GitHub with a reproducible sample app and the gen-l10n configuration '
1444-
'that was used.'
1445-
);
1490+
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
1491+
'an issue with the localizations generation tool. Please file an issue '
1492+
'on GitHub with a reproducible sample app and the gen-l10n configuration '
1493+
'that was used.');
14461494
}

lib/providers/results/format.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,15 @@ class ResultsFormatProvider {
6767
return Colors.transparent;
6868
}
6969
}
70+
71+
int getSessionIndexForFormulaSeries(List sessions, String search) {
72+
int c = 0;
73+
for (var session in sessions) {
74+
if (session['SessionName'].toLowerCase().contains(search.toLowerCase())) {
75+
return c;
76+
}
77+
c++;
78+
}
79+
return 0;
80+
}
7081
}

lib/providers/results/requests.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ResultsRequestsProvider {
9191
championship == 'F1 Academy') {
9292
return FormulaSeries().getSessionResults(
9393
meetingId,
94-
sessionIndex,
94+
sessionIndex: (sessionIndex - 1).toString(),
9595
);
9696
} else {
9797
return [];
@@ -137,7 +137,8 @@ class ResultsRequestsProvider {
137137
championship == 'F1 Academy') {
138138
return FormulaSeries().getSessionResults(
139139
meetingId!,
140-
int.parse(sessionId!),
140+
sessionIndex: sessionId,
141+
sessionName: 'Race',
141142
);
142143
} else {
143144
return [];
@@ -169,7 +170,8 @@ class ResultsRequestsProvider {
169170
championship == 'F1 Academy') {
170171
return await FormulaSeries().getSessionResults(
171172
meetingId!,
172-
int.parse(sessionId!),
173+
sessionIndex: sessionId,
174+
sessionName: 'Sprint Race',
173175
);
174176
} else {
175177
return [];
@@ -182,6 +184,7 @@ class ResultsRequestsProvider {
182184
String? sessionId, {
183185
Race? race,
184186
String? meetingId,
187+
String? sessionName,
185188
}) async {
186189
String championship = Hive.box('settings')
187190
.get('championship', defaultValue: 'Formula 1') as String;
@@ -219,7 +222,8 @@ class ResultsRequestsProvider {
219222
championship == 'F1 Academy') {
220223
return await FormulaSeries().getSessionResults(
221224
meetingId!,
222-
int.parse(sessionId!),
225+
sessionIndex: sessionId,
226+
sessionName: 'Qualifying',
223227
);
224228
} else {
225229
return [];

0 commit comments

Comments
 (0)