From ff4b5961216229c3717f0d2f46e8965a22fe06aa Mon Sep 17 00:00:00 2001 From: Hyperling Date: Mon, 4 May 2026 17:05:59 -0700 Subject: [PATCH] Make the spots clickable and have them increment their inner value. --- lib/main.dart | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index e4fadeb..d07b1d0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -57,7 +57,7 @@ class GameBoard extends StatelessWidget { Column(children: [BoardSpot(text: "5,1")]), ], ), - BoardSpot(text: text), + BoardSpot(text: text, w: 75, h: 200), ], ), // Player 2 Goal @@ -69,19 +69,35 @@ class GameBoard extends StatelessWidget { } } -class BoardSpot extends StatelessWidget { +class BoardSpot extends StatefulWidget { final String text; final double w; final double h; BoardSpot({super.key, required this.text, this.w = 50, this.h = 50}); + @override + State createState() => _BoardSpotState(); +} + +class _BoardSpotState extends State { + var _marbles = 4; @override Widget build(BuildContext context) { - return SizedBox( - width: w, - height: h, - child: Center(child: Text(text, textAlign: TextAlign.center)), + return GestureDetector( + // 2. Handle the tap + onTap: () { + // 3. Update the state + setState(() { + _marbles++; + }); + }, + // 4. The sized box containing the text + child: SizedBox( + width: widget.w, + height: widget.h, + child: Center(child: Text("$_marbles", textAlign: TextAlign.center)), + ), ); } }