1

I have this list

List? mcq;

Now, when after adding values in it, when I try to print the values on the app screen using the Text widget it gives a null error.

child: TextButton(
    child: Text(mcq?[0]),
    onPressed: () => {}),

It says type 'Null' is not a subtype of type 'String'.

If I remove the ? it says [] cannot be unconditionally invoked because the receiver can be null.

Then how do I print the values of a list using Text widget?

1 Answer 1

1

You need set a default value incase it get null, like this:

child: TextButton(
    child: Text(mcq?[0]?? "some thing"),//<---- add this
    onPressed: () => {}),
Sign up to request clarification or add additional context in comments.

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.