Skip to content

Commit

Permalink
feat: use a router for navigation (#185)
Browse files Browse the repository at this point in the history
* [router] add home and article

* [router] add more routes; make video and article reachable only from url!

* [router] add drivers and teams

* [router] add 404, circuit, free practice, settings without update function

* [router] add results, support routes with bbbuttons

* [router] fix

* [router] improve circuit screen when coming from url

* [router] make results available from url too

* [router] add schedule and standings

* [router] add racehub

* [router] add all results routes

* [router] forgot this one

* [shared links] fix texts, improve handler

* [router] translate 404 page

* [router] review fixes
  • Loading branch information
BrightDV authored Feb 24, 2025
1 parent 6e688dd commit a5831fb
Show file tree
Hide file tree
Showing 30 changed files with 1,494 additions and 868 deletions.
68 changes: 68 additions & 0 deletions lib/Screens/404.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This file is part of BoxBox (https://github.com/BrightDV/BoxBox).
*
* BoxBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BoxBox is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with BoxBox. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (c) 2022-2024, BrightDV
*/

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';

class ErrorNotFoundScreen extends StatelessWidget {
final String? route;
const ErrorNotFoundScreen({super.key, this.route});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text(
'Box, Box!',
style: TextStyle(
fontWeight: FontWeight.w700,
),
),
backgroundColor: Theme.of(context).colorScheme.onPrimary,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.only(bottom: 5),
child: Text(
AppLocalizations.of(context)!.offtrack,
style: TextStyle(fontSize: 24),
),
),
Padding(
padding: EdgeInsets.only(bottom: 30),
child: Text(
route ?? '',
style: TextStyle(fontSize: 14),
),
),
ElevatedButton(
onPressed: () => context.go("/"),
child: Text(AppLocalizations.of(context)!.offtrackSub),
),
],
),
),
);
}
}
128 changes: 85 additions & 43 deletions lib/Screens/circuit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* Copyright (c) 2022-2024, BrightDV
*/

import 'package:boxbox/Screens/article.dart';
import 'package:boxbox/Screens/race_details.dart';
import 'package:boxbox/api/event_tracker.dart';
import 'package:boxbox/api/formula1.dart';
import 'package:boxbox/api/formulae.dart';
Expand All @@ -36,6 +34,7 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:go_router/go_router.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

Expand Down Expand Up @@ -107,10 +106,12 @@ class CircuitScreen extends StatelessWidget {
Icon(
Icons.arrow_forward_rounded,
),
RaceDetailsScreen(
race,
false, // offline
),
route: 'results',
pathParameters: {'meetingId': race.meetingId},
extra: {
'race': race,
'hasSprint': false, // offline
},
)
: snapshot.hasData
? Column(
Expand All @@ -123,21 +124,23 @@ class CircuitScreen extends StatelessWidget {
Icon(
Icons.arrow_forward_rounded,
),
RaceDetailsScreen(
scheduleLastSavedFormat == 'ergast'
route: 'results',
pathParameters: {'meetingId': race.meetingId},
extra: {
'race': scheduleLastSavedFormat == 'ergast'
? race
: snapshot
.data!['raceCustomBBParameter'],
championship == 'Formula E'
'hasSprint': championship == 'Formula E'
? false
: snapshot.data!['meetingContext']
['timetables'][2]['session'] ==
's',
sessions: championship == 'Formula E'
'sessions': championship == 'Formula E'
? snapshot.data![
'sessionsIdsCustomBBParameter']
: null,
),
},
),
snapshot.data!['links'] != null &&
snapshot.data!['links'].isNotEmpty &&
Expand All @@ -148,8 +151,10 @@ class CircuitScreen extends StatelessWidget {
Icon(
Icons.arrow_forward_rounded,
),
ArticleScreen(
snapshot.data!['links'].last['url']
route: 'article',
pathParameters: {
'id': snapshot
.data!['links'].last['url']
.endsWith('.html')
? snapshot
.data!['links'].last['url']
Expand All @@ -158,9 +163,8 @@ class CircuitScreen extends StatelessWidget {
.data!['links'].last['url']
.split('.')
.last,
'',
true,
),
},
extra: {'isFromLink': true},
)
: Container(),
championship == 'Formula 1'
Expand All @@ -170,7 +174,7 @@ class CircuitScreen extends StatelessWidget {
Icon(
Icons.map_outlined,
),
CircuitMapScreen(
widget: CircuitMapScreen(
scheduleLastSavedFormat == 'ergast'
? race.circuitId
: Convert()
Expand Down Expand Up @@ -220,10 +224,12 @@ class CircuitScreen extends StatelessWidget {
Icon(
Icons.arrow_forward_rounded,
),
RaceDetailsScreen(
race,
false, // offline
),
route: 'results',
pathParameters: {'meetingId': race.meetingId},
extra: {
'race': race,
'hasSprint': false, //offline
},
),
),
),
Expand All @@ -248,6 +254,9 @@ class CircuitScreen extends StatelessWidget {
pinned: true,
centerTitle: true,
flexibleSpace: FlexibleSpaceBar(
background: RaceImageProvider(
snapshot.data!['raceCustomBBParameter'],
),
title: Text(
snapshot.data!['raceCustomBBParameter']
.raceName,
Expand All @@ -269,13 +278,19 @@ class CircuitScreen extends StatelessWidget {
Icon(
Icons.arrow_forward_rounded,
),
RaceDetailsScreen(
snapshot.data!['raceCustomBBParameter'],
snapshot.data!['meetingContext']
['timetables'][2]['session'] ==
's',
isFromRaceHub: true,
),
route: 'results',
pathParameters: {
'meetingId': snapshot
.data!['meetingContext']['meetingKey']
},
extra: {
'race':
snapshot.data!['raceCustomBBParameter'],
'hasSprint':
snapshot.data!['meetingContext']
['timetables'][2]['session'] ==
's',
},
),
snapshot.data!['links'] != null &&
snapshot.data!['links'].isNotEmpty &&
Expand All @@ -286,8 +301,10 @@ class CircuitScreen extends StatelessWidget {
Icon(
Icons.arrow_forward_rounded,
),
ArticleScreen(
snapshot.data!['links'][1]['url']
route: 'article',
pathParameters: {
'id': snapshot.data!['links'][1]
['url']
.endsWith('.html')
? snapshot.data!['links'][1]
['url']
Expand All @@ -296,9 +313,32 @@ class CircuitScreen extends StatelessWidget {
['url']
.split('.')
.last,
'',
true,
},
extra: {'isFromLink': true},
)
: Container(),
championship == 'Formula 1'
? BoxBoxButton(
AppLocalizations.of(context)!
.grandPrixMap,
Icon(
Icons.map_outlined,
),
widget: CircuitMapScreen(
scheduleLastSavedFormat == 'ergast'
? snapshot
.data![
'raceCustomBBParameter']
.circuitId
: Convert()
.circuitNameFromFormulaOneToErgastForCircuitPoints(
snapshot
.data![
'raceCustomBBParameter']
.country,
),
),
isDialog: true,
)
: Container(),
snapshot.data!['raceResults'] != null &&
Expand Down Expand Up @@ -688,17 +728,19 @@ class RaceResults extends StatelessWidget {
bottomRight: Radius.circular(15),
),
child: ElevatedButton(
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RaceDetailsScreen(
race,
snapshot.data!['meetingContext']['timetables'][2]
['session'] ==
's',
tab: 10,
),
),
onPressed: () => context.pushNamed(
'results',
pathParameters: {
'meetingId': snapshot.data!['meetingContext']
['meetingKey'],
},
extra: {
'race': race,
'hasSprint': snapshot.data!['meetingContext']
['timetables'][2]['session'] ==
's',
'tab': 10,
},
),
style: ElevatedButton.styleFrom(
shape: const ContinuousRectangleBorder(
Expand Down
Loading

0 comments on commit a5831fb

Please sign in to comment.