generated from me/template-mit
Make the spots clickable and have them increment their inner value.
This commit is contained in:
@@ -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<BoardSpot> createState() => _BoardSpotState();
|
||||
}
|
||||
|
||||
class _BoardSpotState extends State<BoardSpot> {
|
||||
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)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user