From dbd492969a9518cb90889441792f5aff6aba2902 Mon Sep 17 00:00:00 2001 From: Andrei Stoica Date: Fri, 27 Dec 2024 21:32:06 -0500 Subject: [PATCH] valid choice --- lib/super.dart | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/super.dart b/lib/super.dart index f1e63f2..965ecd8 100644 --- a/lib/super.dart +++ b/lib/super.dart @@ -51,6 +51,9 @@ class _SuperGameState extends State { } } + bool _checkValidChoice(List game, int index) => + game[index] == TTCState.empty; + Widget _subGameDialog(int subGame) { return Dialog( child: Padding( @@ -58,13 +61,20 @@ class _SuperGameState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - Text( - "${Util.stateText(turn)} select cell", - style: const TextStyle(fontWeight: FontWeight.bold), + Padding( + padding: const EdgeInsets.only(bottom: 5), + child: Text( + "${Util.stateText(turn)} select cell", + style: const TextStyle(fontWeight: FontWeight.bold), + ), ), TTCGame( turn: turn, cellOnTapCallback: (int i) { + if (!_checkValidChoice(data[subGame], i)) { + return; + } + nextPlay = i; setState(() { data[subGame][i] = turn; @@ -74,15 +84,18 @@ class _SuperGameState extends State { }, data: data[subGame], ), - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - ElevatedButton( - onPressed: () { - Navigator.pop(context); - }, - child: const Text("Close")) - ], + Padding( + padding: const EdgeInsets.only(top: 5), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + ElevatedButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text("Close")) + ], + ), ), ], ),