Make the spots clickable and have them increment their inner value.

This commit is contained in:
2026-05-04 17:05:59 -07:00
parent df9c2dc9c9
commit ff4b596121

View File

@@ -57,7 +57,7 @@ class GameBoard extends StatelessWidget {
Column(children: [BoardSpot(text: "5,1")]), Column(children: [BoardSpot(text: "5,1")]),
], ],
), ),
BoardSpot(text: text), BoardSpot(text: text, w: 75, h: 200),
], ],
), ),
// Player 2 Goal // Player 2 Goal
@@ -69,19 +69,35 @@ class GameBoard extends StatelessWidget {
} }
} }
class BoardSpot extends StatelessWidget { class BoardSpot extends StatefulWidget {
final String text; final String text;
final double w; final double w;
final double h; final double h;
BoardSpot({super.key, required this.text, this.w = 50, this.h = 50}); BoardSpot({super.key, required this.text, this.w = 50, this.h = 50});
@override
State<BoardSpot> createState() => _BoardSpotState();
}
class _BoardSpotState extends State<BoardSpot> {
var _marbles = 4;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SizedBox( return GestureDetector(
width: w, // 2. Handle the tap
height: h, onTap: () {
child: Center(child: Text(text, textAlign: TextAlign.center)), // 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)),
),
); );
} }
} }