Skip to content

Commit

Permalink
feat: Duration Edit for Bout
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Jan 16, 2024
1 parent 61746f7 commit 9c34191
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion wrestling_scoreboard_client/lib/ui/edit/bout_edit.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wrestling_scoreboard_client/data/bout_result.dart';
Expand Down Expand Up @@ -30,12 +31,14 @@ abstract class BoutEditState<T extends BoutEdit> extends State<T> implements Abs
WeightClass? _weightClass;
Participation? _redParticipation;
Participation? _blueParticipation;
int? _durationInSecs;

Future<List<WeightClass>> get availableWeightClasses;

@override
void initState() {
super.initState();
_durationInSecs = widget.bout?.duration.inSeconds;
_winnerRole = widget.bout?.winnerRole;
_boutResult = widget.bout?.result;
_weightClass = widget.bout?.weightClass;
Expand Down Expand Up @@ -131,6 +134,21 @@ abstract class BoutEditState<T extends BoutEdit> extends State<T> implements Abs
),
),
),
ListTile(
leading: const Icon(Icons.timelapse),
title: TextFormField(
initialValue: _durationInSecs.toString(),
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(vertical: 20),
labelText: '${localizations.duration} (seconds)',
),
inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.allow(RegExp(r'^\d{1,4}'))],
onSaved: (String? value) {
_durationInSecs = int.tryParse(value ?? '') ?? 0;
},
),
),
];

return Form(
Expand Down Expand Up @@ -168,7 +186,7 @@ abstract class BoutEditState<T extends BoutEdit> extends State<T> implements Abs
winnerRole: _winnerRole,
r: await updateParticipantState(_redParticipation, widget.bout?.r),
b: await updateParticipantState(_blueParticipation, widget.bout?.b),
duration: widget.bout?.duration ?? Duration.zero,
duration: Duration(seconds: _durationInSecs ?? 0),
pool: widget.bout?.pool,
);

Expand Down

0 comments on commit 9c34191

Please sign in to comment.