Skip to content

Commit

Permalink
add reset players
Browse files Browse the repository at this point in the history
  • Loading branch information
j7126 committed Apr 3, 2024
1 parent 3d70b0f commit 0e695e3
Showing 1 changed file with 81 additions and 7 deletions.
88 changes: 81 additions & 7 deletions lib/pages/life_counter_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class _LifeCounterPageState extends State<LifeCounterPage> {
});
}

void resetPlayers() {
setState(() {
players.clear();
setupPlayers();
});
}

void setupPlayers() {
setState(() {
if (numPlayers > players.length) {
Expand Down Expand Up @@ -115,19 +122,80 @@ class _LifeCounterPageState extends State<LifeCounterPage> {
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('The life counters will be reset.'),
title: Column(
children: [
const Text('The life counters will be reset'),
const Gap(16.0),
Row(
children: [
TextButton(
child: const Text('Reset Players'),
onPressed: () async {
Navigator.of(context).pop(false);
_showResetPlayersDialog();
},
),
const Spacer(),
TextButton(
child: const Text('Cancel'),
onPressed: () {
Navigator.of(context).pop(false);
},
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: FilledButton(
style: const ButtonStyle(
padding: MaterialStatePropertyAll(
EdgeInsets.symmetric(horizontal: 16.0),
),
backgroundColor: MaterialStatePropertyAll(Colors.red),
foregroundColor: MaterialStatePropertyAll(Colors.white),
),
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text('Reset'),
),
),
],
)
],
),
);
},
);
}

Future<bool?> _showResetPlayersWarning() {
return showDialog<bool>(
context: context,
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('The player configuration will be reset!'),
actions: <Widget>[
TextButton(
child: const Text('Cancel'),
onPressed: () {
Navigator.of(context).pop(false);
},
),
TextButton(
child: const Text('Continue'),
onPressed: () {
Navigator.of(context).pop(true);
},
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: FilledButton(
style: const ButtonStyle(
padding: MaterialStatePropertyAll(
EdgeInsets.symmetric(horizontal: 16.0),
),
backgroundColor: MaterialStatePropertyAll(Colors.red),
foregroundColor: MaterialStatePropertyAll(Colors.white),
),
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text('Reset'),
),
),
],
);
Expand All @@ -142,11 +210,17 @@ class _LifeCounterPageState extends State<LifeCounterPage> {
}

void _showResetGameDialog() async {
var result = isGameReset ? false : await _showResetWarning();
var result = await _showResetWarning();

if (result ?? false) resetGame();
}

void _showResetPlayersDialog() async {
var result = await _showResetPlayersWarning();

if (result ?? false) resetPlayers();
}

void _showPlanechase() {
showDialog(
context: context,
Expand Down

0 comments on commit 0e695e3

Please sign in to comment.