Skip to content

Commit

Permalink
feat: Handling unavailable data
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Dec 2, 2023
1 parent 1044d31 commit 0e163ec
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 74 deletions.
1 change: 1 addition & 0 deletions wrestling_scoreboard_client/lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"noItems": "Keine Einträge vorhanden.",
"mandatoryField": "Das ist ein Pflichtfeld.",
"noWebSocketConnection": "Die Verbindung zum Server konnte nicht aufgebaut werden oder wurde unterbrochen.",
"notFoundException": "Element wurde nicht gefunden :/",
"invalidParameterException": "Die Änderung war nicht erfolgreich, bitte überprüfe deine Eingabeparameter.",
"retry": "Erneut versuchen",

Expand Down
1 change: 1 addition & 0 deletions wrestling_scoreboard_client/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"noItems": "No items available.",
"mandatoryField": "This is a mandatory field.",
"noWebSocketConnection": "The connection to the server could not be established or was interrupted.",
"notFoundException": "Element was not found :/",
"invalidParameterException": "The change was not successful, please check your input parameters.",
"retry": "Retry",

Expand Down
11 changes: 8 additions & 3 deletions wrestling_scoreboard_client/lib/ui/components/consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import 'package:wrestling_scoreboard_common/common.dart';
class SingleConsumer<T extends DataObject> extends StatefulWidget {
final int? id;
final T? initialData;
final Widget Function(BuildContext context, T data) builder;
final Widget Function(BuildContext context, T? data) builder;

const SingleConsumer({required this.id, this.initialData, required this.builder, Key? key}) : super(key: key);
const SingleConsumer({
required this.id,
this.initialData,
required this.builder,
Key? key,
}) : super(key: key);

@override
State<StatefulWidget> createState() => SingleConsumerState<T>();
Expand All @@ -30,7 +35,7 @@ class SingleConsumerState<T extends DataObject> extends State<SingleConsumer<T>>
return StreamBuilder(
stream: webSocketConnectionStream,
builder: (context, snapshot) => widget.id == null
? const ExceptionWidget('Element not found!')
? widget.builder(context, null)
: StreamBuilder<T>(
stream:
widget.id == null ? null : dataProvider.streamSingle<T>(widget.id!, init: widget.initialData == null),
Expand Down
27 changes: 17 additions & 10 deletions wrestling_scoreboard_client/lib/ui/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:wrestling_scoreboard_client/ui/components/consumer.dart';
import 'package:wrestling_scoreboard_client/ui/components/exception.dart';
import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart';
import 'package:wrestling_scoreboard_client/ui/edit/club_edit.dart';
import 'package:wrestling_scoreboard_client/ui/edit/league_edit.dart';
Expand Down Expand Up @@ -99,11 +100,14 @@ class HomeState extends State<Home> {
(e) => SingleConsumer<Club>(
id: e.id!,
initialData: e,
builder: (context, data) => ContentItem(
title: data.name,
icon: Icons.foundation,
onTap: () => handleSelectedClub(data, context),
),
builder: (context, data) {
if (data == null) return ExceptionWidget(localizations.notFoundException);
return ContentItem(
title: data.name,
icon: Icons.foundation,
onTap: () => handleSelectedClub(data, context),
);
},
),
),
);
Expand All @@ -123,11 +127,14 @@ class HomeState extends State<Home> {
(e) => SingleConsumer<League>(
id: e.id!,
initialData: e,
builder: (context, data) => ContentItem(
title: data.name,
icon: Icons.emoji_events,
onTap: () => handleSelectedLeague(data, context),
),
builder: (context, data) {
if (data == null) return ExceptionWidget(localizations.notFoundException);
return ContentItem(
title: data.name,
icon: Icons.emoji_events,
onTap: () => handleSelectedLeague(data, context),
);
},
),
),
);
Expand Down
19 changes: 11 additions & 8 deletions wrestling_scoreboard_client/lib/ui/match/match_sequence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:wrestling_scoreboard_client/data/fight_result.dart';
import 'package:wrestling_scoreboard_client/data/fight_role.dart';
import 'package:wrestling_scoreboard_client/data/wrestling_style.dart';
import 'package:wrestling_scoreboard_client/ui/components/consumer.dart';
import 'package:wrestling_scoreboard_client/ui/components/exception.dart';
import 'package:wrestling_scoreboard_client/ui/fight/fight_screen.dart';
import 'package:wrestling_scoreboard_client/ui/overview/team_match_overview.dart';
import 'package:wrestling_scoreboard_client/util/units.dart';
Expand All @@ -23,6 +24,7 @@ class MatchSequence extends StatelessWidget {

@override
Widget build(BuildContext context) {
final localizations = AppLocalizations.of(context)!;
final navigator = Navigator.of(context);

double width = MediaQuery.of(context).size.width;
Expand All @@ -33,6 +35,7 @@ class MatchSequence extends StatelessWidget {
id: id,
initialData: teamMatch,
builder: (context, match) {
if (match == null) return ExceptionWidget(localizations.notFoundException);
return Scaffold(
bottomNavigationBar: BottomAppBar(
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Expand Down Expand Up @@ -177,7 +180,7 @@ class FightListItem extends StatelessWidget {
child: Container(
color: fight.winnerRole == FightRole.red ? Colors.red.shade800 : null,
child: Center(
child: Text(pState.classificationPoints?.toString() ?? '-',
child: Text(pState?.classificationPoints?.toString() ?? '-',
style: fontStyleDefault),
),
)),
Expand All @@ -190,7 +193,7 @@ class FightListItem extends StatelessWidget {
child: Container(
color: fight.winnerRole == FightRole.red ? Colors.red.shade800 : null,
child: Center(
child: pState.classificationPoints != null
child: pState?.classificationPoints != null
? Text(
ParticipantState.getTechnicalPoints(actions, FightRole.red)
.toString(),
Expand Down Expand Up @@ -220,17 +223,17 @@ class FightListItem extends StatelessWidget {
flex: 70,
child: Container(
color:
data.winnerRole != null ? getColorFromFightRole(data.winnerRole!).shade800 : null,
data?.winnerRole != null ? getColorFromFightRole(data!.winnerRole!).shade800 : null,
child: Center(
child: Text(getAbbreviationFromFightResult(data.result, context),
child: Text(getAbbreviationFromFightResult(data?.result, context),
style: TextStyle(fontSize: fontSizeDefault * 0.7)),
),
)),
Expanded(
flex: 50,
child: Center(
child: data.winnerRole != null
? Text(durationToString(data.duration),
child: data?.winnerRole != null
? Text(durationToString(data!.duration),
style: TextStyle(fontSize: fontSizeDefault / 2))
: null,
)),
Expand All @@ -254,7 +257,7 @@ class FightListItem extends StatelessWidget {
child: Container(
color: fight.winnerRole == FightRole.blue ? Colors.blue.shade800 : null,
child: Center(
child: Text(pState.classificationPoints?.toString() ?? '-',
child: Text(pState?.classificationPoints?.toString() ?? '-',
style: fontStyleDefault),
),
)),
Expand All @@ -267,7 +270,7 @@ class FightListItem extends StatelessWidget {
child: Container(
color: fight.winnerRole == FightRole.blue ? Colors.blue.shade800 : null,
child: Center(
child: pState.classificationPoints != null
child: pState?.classificationPoints != null
? Text(
ParticipantState.getTechnicalPoints(actions, FightRole.blue)
.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:wrestling_scoreboard_client/ui/components/consumer.dart';
import 'package:wrestling_scoreboard_client/ui/components/exception.dart';
import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart';
import 'package:wrestling_scoreboard_client/ui/components/info.dart';
import 'package:wrestling_scoreboard_client/ui/edit/club_edit.dart';
Expand All @@ -28,6 +29,7 @@ class ClubOverview extends StatelessWidget {
id: id,
initialData: club,
builder: (context, data) {
if (data == null) return ExceptionWidget(localizations.notFoundException);
final description = InfoWidget(
obj: data,
editPage: ClubEdit(
Expand Down Expand Up @@ -70,8 +72,11 @@ class ClubOverview extends StatelessWidget {
items: teams.map((team) => SingleConsumer<Team>(
id: team.id,
initialData: team,
builder: (context, team) => ContentItem(
title: team.name, icon: Icons.group, onTap: () => handleSelectedTeam(team, context)))),
builder: (context, team) {
if (team == null) return ExceptionWidget(localizations.notFoundException);
return ContentItem(
title: team.name, icon: Icons.group, onTap: () => handleSelectedTeam(team, context));
})),
);
},
),
Expand Down
18 changes: 12 additions & 6 deletions wrestling_scoreboard_client/lib/ui/overview/league_overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:wrestling_scoreboard_client/data/wrestling_style.dart';
import 'package:wrestling_scoreboard_client/ui/components/consumer.dart';
import 'package:wrestling_scoreboard_client/ui/components/exception.dart';
import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart';
import 'package:wrestling_scoreboard_client/ui/components/info.dart';
import 'package:wrestling_scoreboard_client/ui/edit/league_edit.dart';
Expand Down Expand Up @@ -31,6 +32,7 @@ class LeagueOverview extends StatelessWidget {
id: id,
initialData: league,
builder: (context, data) {
if (data == null) return ExceptionWidget(localizations.notFoundException);
final description = InfoWidget(
obj: data,
editPage: LeagueEdit(
Expand Down Expand Up @@ -62,7 +64,7 @@ class LeagueOverview extends StatelessWidget {
description,
ManyConsumer<LeagueTeamParticipation, League>(
filterObject: data,
builder: (BuildContext context, List<LeagueTeamParticipation> team) {
builder: (BuildContext context, List<LeagueTeamParticipation> teamParticipations) {
return ListGroup(
header: HeadingItem(
title: localizations.participatingTeams,
Expand All @@ -78,11 +80,12 @@ class LeagueOverview extends StatelessWidget {
),
),
),
items: team.map(
items: teamParticipations.map(
(e) => SingleConsumer<LeagueTeamParticipation>(
id: e.id,
initialData: e,
builder: (context, data) {
if (data == null) return ExceptionWidget(localizations.notFoundException);
return ContentItem(
title: data.team.name,
icon: Icons.group,
Expand Down Expand Up @@ -114,10 +117,13 @@ class LeagueOverview extends StatelessWidget {
return SingleConsumer<LeagueWeightClass>(
id: e.id,
initialData: e,
builder: (context, data) => ContentItem(
title: '${data.weightClass.name} ${styleToString(data.weightClass.style, context)}',
icon: Icons.fitness_center,
onTap: () => handleSelectedWeightClass(data, context)),
builder: (context, data) {
if (data == null) return ExceptionWidget(localizations.notFoundException);
return ContentItem(
title: '${data.weightClass.name} ${styleToString(data.weightClass.style, context)}',
icon: Icons.fitness_center,
onTap: () => handleSelectedWeightClass(data, context));
},
);
}),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:wrestling_scoreboard_client/ui/components/consumer.dart';
import 'package:wrestling_scoreboard_client/ui/components/exception.dart';
import 'package:wrestling_scoreboard_client/ui/edit/league_weight_class_edit.dart';
import 'package:wrestling_scoreboard_client/ui/overview/weight_class_overview.dart';
import 'package:wrestling_scoreboard_client/util/network/data_provider.dart';
Expand All @@ -21,6 +22,7 @@ class LeagueWeightClassOverview extends WeightClassOverview {
id: id,
initialData: leagueWeightClass,
builder: (context, data) {
if (data == null) return ExceptionWidget(localizations.notFoundException);
return buildOverview(context,
classLocale: localizations.weightClass,
editPage: LeagueWeightClassEdit(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:wrestling_scoreboard_client/ui/components/consumer.dart';
import 'package:wrestling_scoreboard_client/ui/components/exception.dart';
import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart';
import 'package:wrestling_scoreboard_client/ui/edit/membership_edit.dart';
import 'package:wrestling_scoreboard_client/ui/overview/person_overview.dart';
Expand All @@ -21,24 +22,27 @@ class MembershipOverview extends PersonOverview {
return SingleConsumer<Membership>(
id: id,
initialData: membership,
builder: (context, membership) => buildOverview(
context,
dataId: membership.person.id!,
initialData: membership.person,
classLocale: localizations.membership,
editPage: MembershipEdit(
membership: membership,
initialClub: membership.club,
),
onDelete: () => dataProvider.deleteSingle(membership),
tiles: [
ContentItem(
title: membership.no ?? '-',
subtitle: localizations.membershipNumber,
icon: Icons.tag,
)
],
),
builder: (context, membership) {
if (membership == null) return ExceptionWidget(localizations.notFoundException);
return buildOverview(
context,
dataId: membership.person.id!,
initialData: membership.person,
classLocale: localizations.membership,
editPage: MembershipEdit(
membership: membership,
initialClub: membership.club,
),
onDelete: () => dataProvider.deleteSingle(membership),
tiles: [
ContentItem(
title: membership.no ?? '-',
subtitle: localizations.membershipNumber,
icon: Icons.tag,
)
],
);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:wrestling_scoreboard_client/data/gender.dart';
import 'package:wrestling_scoreboard_client/ui/components/consumer.dart';
import 'package:wrestling_scoreboard_client/ui/components/exception.dart';
import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart';
import 'package:wrestling_scoreboard_client/ui/components/info.dart';
import 'package:wrestling_scoreboard_client/ui/overview/common.dart';
Expand Down Expand Up @@ -29,6 +30,7 @@ abstract class PersonOverview extends StatelessWidget implements AbstractOvervie
id: dataId,
initialData: initialData,
builder: (context, person) {
if (person == null) return ExceptionWidget(localizations.notFoundException);
final description = InfoWidget(
obj: person,
editPage: editPage,
Expand Down
Loading

0 comments on commit 0e163ec

Please sign in to comment.