Dice image not changing on onPress
setState not setting dice image for random number
child: Image.asset('images/dice$leftDiceNumber.png'), not working but
child: Image.asset('images/dice2.png'), is working that means hard code is working
var leftDiceNumber = 3; getting only dice3.png as i initialize it for leftDiceNumber
Please help for getting random image when onPress
No errors in App
class DicePage extends StatefulWidget {
const DicePage({Key? key}) : super(key: key);
@override
_DicePageState createState() => _DicePageState();
}
class _DicePageState extends State<DicePage> {
@override
Widget build(BuildContext context) {
var leftDiceNumber = 3;
return Center(
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () {
setState(() {
leftDiceNumber = Random().nextInt(6) + 1;
print(leftDiceNumber); // getting value in console
});
},
child: Image.asset('images/dice$leftDiceNumber.png'),
//child: Image.asset('images/dice1.png'), // ( works )
),),],
),);}}