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)), + ), ); } }