1

is it possible to dynamically access variables? The code below demonstrates what I mean.

for (var i = 0; i < dataList.length; i++) {
  var product1 = 20;
  var product2 = 30;

  product$i = 30;
}

2 Answers 2

3

No, that is not possible in Dart and is also not what you really want to do. Instead, you should use List or Map to contain your values if you need to access them in some dynamic way. By doing so, you can achieve statically type safety since Dart will be able to check the types before even running your program.

Sign up to request clarification or add additional context in comments.

Comments

-1

Im not sure if its possible or not... But you could do something like this

var product= new Map()

for (var i = 0; i < dataList.length; i++) {
  var product1 = 20;
  var product2 = 30;

  product[i] = 30;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.