Skip to content

Commit

Permalink
Fix null value error on broadcast round start date
Browse files Browse the repository at this point in the history
  • Loading branch information
julien4215 committed Dec 8, 2024
1 parent 64daba1 commit 290e8d9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
3 changes: 2 additions & 1 deletion lib/src/model/broadcast/broadcast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class BroadcastRound with _$BroadcastRound {
required String name,
required RoundStatus status,
required DateTime? startsAt,
DateTime? finishedAt,
required DateTime? finishedAt,
required bool startsAfterPrevious,
}) = _BroadcastRound;
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/model/broadcast/broadcast_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ BroadcastRound _roundFromPick(RequiredPick pick) {
status: status,
startsAt: pick('startsAt').asDateTimeFromMillisecondsOrNull(),
finishedAt: pick('finishedAt').asDateTimeFromMillisecondsOrNull(),
startsAfterPrevious: pick('startsAfterPrevious').asBoolOrFalse(),
);
}

Expand Down
14 changes: 8 additions & 6 deletions lib/src/view/broadcast/broadcast_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ class BroadcastGridItem extends StatefulWidget {
final Broadcast broadcast;
final ImageColorWorker worker;

BroadcastGridItem.loading(this.worker)
: broadcast = Broadcast(
tour: const BroadcastTournamentData(
const BroadcastGridItem.loading(this.worker)
: broadcast = const Broadcast(
tour: BroadcastTournamentData(
id: BroadcastTournamentId(''),
name: '',
imageUrl: null,
Expand All @@ -233,13 +233,15 @@ class BroadcastGridItem extends StatefulWidget {
),
),
round: BroadcastRound(
id: const BroadcastRoundId(''),
id: BroadcastRoundId(''),
name: '',
status: RoundStatus.finished,
startsAt: DateTime.now(),
startsAt: null,
finishedAt: null,
startsAfterPrevious: false,
),
group: null,
roundToLinkId: const BroadcastRoundId(''),
roundToLinkId: BroadcastRoundId(''),
);

@override
Expand Down
57 changes: 30 additions & 27 deletions lib/src/view/broadcast/broadcast_round_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,37 +332,40 @@ class _RoundSelectorState extends ConsumerState<_RoundSelectorMenu> {
return BottomSheetScrollableContainer(
scrollController: widget.scrollController,
children: [
for (final round in widget.rounds)
for (final (index, round) in widget.rounds.indexed)
PlatformListTile(
key: round.id == widget.selectedRoundId ? currentRoundKey : null,
selected: round.id == widget.selectedRoundId,
title: Text(round.name),
trailing: switch (round.status) {
RoundStatus.finished => Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(_dateFormat.format(round.startsAt!)),
const SizedBox(width: 5.0),
Icon(Icons.check, color: context.lichessColors.good),
],
),
RoundStatus.live => Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(_dateFormat.format(round.startsAt!)),
const SizedBox(width: 5.0),
Icon(Icons.circle, color: context.lichessColors.error),
],
),
RoundStatus.upcoming => Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(_dateFormat.format(round.startsAt!)),
const SizedBox(width: 5.0),
const Icon(Icons.calendar_month, color: Colors.grey),
],
),
},
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (round.startsAt != null || round.startsAfterPrevious) ...[
Text(
round.startsAt != null
? _dateFormat.format(round.startsAt!)
: context.l10n.broadcastStartsAfter(
widget.rounds[index - 1].name,
),
),
const SizedBox(width: 5.0),
],
switch (round.status) {
RoundStatus.finished => Icon(
Icons.check,
color: context.lichessColors.good,
),
RoundStatus.live => Icon(
Icons.circle,
color: context.lichessColors.error,
),
RoundStatus.upcoming => const Icon(
Icons.calendar_month,
color: Colors.grey,
),
},
],
),
onTap: () {
widget.setRoundId(round.id);
Navigator.of(context).pop();
Expand Down

0 comments on commit 290e8d9

Please sign in to comment.