1

I have the following code:

_places.forEach((element) {
  final String name = element.name;
  print(element);
  places.add(Card(
      child: InkWell(
          splashColor: Colors.blue.withAlpha(30),
          onTap: () {
            print('Card tapped.');
          },
          child: const SizedBox(
              width: 375,
              height: 100,
              child: Padding(
                padding: EdgeInsets.all(15.00),
                child: Text(
                  name
                )
              )))));
});

The problem I'm having is that the variable name is giving an error when using it inside Text.

Error: Not a constant expression.

1 Answer 1

7

Please try removing the const from SizedBox. SizedBox expecting data to be constant, but the variable text can change on runtime. const is used in a case the value is constant from compile time.

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

1 Comment

Perfect. Thank you! I'll accept the answer as soon as I'm allowed

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.