fix: button view logic
This commit is contained in:
@@ -50,7 +50,7 @@ class _MatchResultViewState extends State<MatchResultView> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
db = Provider.of<AppDatabase>(context, listen: false);
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
ruleset = widget.match.game.ruleset;
|
ruleset = Ruleset.highestScore; //widget.match.game.ruleset;
|
||||||
canSave = !rulesetSupportsScoreEntry();
|
canSave = !rulesetSupportsScoreEntry();
|
||||||
|
|
||||||
allPlayers = widget.match.players;
|
allPlayers = widget.match.players;
|
||||||
@@ -93,16 +93,13 @@ class _MatchResultViewState extends State<MatchResultView> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
automaticallyImplyLeading: !isLiveEditMode,
|
leading: IconButton(
|
||||||
leading: !isLiveEditMode
|
icon: const Icon(Icons.close),
|
||||||
? IconButton(
|
onPressed: () {
|
||||||
icon: const Icon(Icons.close),
|
widget.onWinnerChanged?.call();
|
||||||
onPressed: () {
|
Navigator.of(context).pop(_selectedPlayer);
|
||||||
widget.onWinnerChanged?.call();
|
},
|
||||||
Navigator.of(context).pop(_selectedPlayer);
|
),
|
||||||
},
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
title: Text(widget.match.name),
|
title: Text(widget.match.name),
|
||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
@@ -212,47 +209,38 @@ class _MatchResultViewState extends State<MatchResultView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (!isLiveEditMode) ...[
|
|
||||||
if (rulesetSupportsScoreEntry())
|
|
||||||
// Button to switch to live edit mode
|
|
||||||
...[
|
|
||||||
CustomWidthButton(
|
|
||||||
text: loc.live_edit_mode,
|
|
||||||
sizeRelativeToWidth: 0.95,
|
|
||||||
buttonType: ButtonType.secondary,
|
|
||||||
onPressed: () => setState(() {
|
|
||||||
isLiveEditMode = true;
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
],
|
|
||||||
|
|
||||||
// Save Changes Button
|
if (rulesetSupportsScoreEntry())
|
||||||
|
// Button to switch to live edit mode
|
||||||
|
...[
|
||||||
CustomWidthButton(
|
CustomWidthButton(
|
||||||
text: loc.save_changes,
|
text: isLiveEditMode ? loc.exit_view : loc.live_edit_mode,
|
||||||
sizeRelativeToWidth: 0.95,
|
|
||||||
onPressed: canSave
|
|
||||||
? () async {
|
|
||||||
final ending = DateTime.now();
|
|
||||||
await db.matchDao.updateMatchEndedAt(
|
|
||||||
matchId: widget.match.id,
|
|
||||||
endedAt: ending,
|
|
||||||
);
|
|
||||||
await _handleSaving();
|
|
||||||
if (!context.mounted) return;
|
|
||||||
Navigator.of(context).pop(_selectedPlayer);
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
] else ...[
|
|
||||||
CustomWidthButton(
|
|
||||||
text: loc.exit_view,
|
|
||||||
sizeRelativeToWidth: 0.95,
|
sizeRelativeToWidth: 0.95,
|
||||||
|
buttonType: ButtonType.secondary,
|
||||||
onPressed: () => setState(() {
|
onPressed: () => setState(() {
|
||||||
isLiveEditMode = false;
|
isLiveEditMode = !isLiveEditMode;
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Save Changes Button
|
||||||
|
CustomWidthButton(
|
||||||
|
text: loc.save_changes,
|
||||||
|
sizeRelativeToWidth: 0.95,
|
||||||
|
onPressed: canSave
|
||||||
|
? () async {
|
||||||
|
final ending = DateTime.now();
|
||||||
|
await db.matchDao.updateMatchEndedAt(
|
||||||
|
matchId: widget.match.id,
|
||||||
|
endedAt: ending,
|
||||||
|
);
|
||||||
|
await _handleSaving();
|
||||||
|
if (!context.mounted) return;
|
||||||
|
Navigator.of(context).pop(_selectedPlayer);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user