I have an array that contains a list of String
var array = [
"table",
"laptop",
"kitchen",
];
and I have a random number:
int i= Random().nextInt(2);
I want to show the random selected item in a text widget something like:
Text("your randomly selected item ist $array[i] ")
but that dosn't work.
How can I do that?
CodePudding user response:
You have to use ${array[i]}
instead of $array[i]
.
CodePudding user response:
When you want to use more than on variable value in string context, you should use {}
like:
Text("your randomly selected item is ${array[i]}")
CodePudding user response:
You have to use like this:
var array = ["table","laptop","kitchen"];
int i= Random().nextInt(array.length);
Text("your randomly selected item ist ${array[i]} ");