I have a row with some dices, I want to change their values based on the simple manipulating the address itself, when I’m having them manually in the children of the row its working all right but when I want to add them as an item to some list then have that list in the children section of the row the code is not working
import 'dart:math';
import 'package:flutter/material.dart';
class AskCom extends StatefulWidget {
const AskCom({super.key});
@override
State<AskCom> createState() => _AskComState();
}
class _AskComState extends State<AskCom> {
int diceV1 = 1;
int diceV2 = 2;
int diceV3 = 3;
List<Widget> diceRow = [];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(children: diceRow
//the working part
//[dice(diceV1),dice(diceV2),dice(diceV3)]
),
const SizedBox(
height: 20,
),
SizedBox(
width: 200,
child: ElevatedButton(
onPressed: () {
setState(() {
diceV1 = Random().nextInt(6) + 1;
diceV2 = Random().nextInt(6) + 1;
diceV3 = Random().nextInt(6) + 1;
});
},
child: const Text('ROLL')),
),
SizedBox(
width: 200,
child: ElevatedButton(
onPressed: () {
setState(() {
diceRow.add(dice(diceV1));
diceRow.add(dice(diceV2));
diceRow.add(dice(diceV3));
});
},
child: const Text('ADD')),
)
],
),
);
}
Expanded dice(diceVal) {
return Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
'assets/images/dice/dice$diceVal.png',
color: Colors.red,
),
),
);
}
}
I tired to call the dice as a mthod or class but both had the same result