I\'m trying to add the option for the quantity to be adjusted but I get an error saying \"A non-null String must be provided to a Text widget\" How do I provide this, to this co
The problem is visible. You're passing null to Text widget. new Text(cart_prod_qty)
This can be due to delay of response from api (if you're using it). Or there is no value in the variable "cart_prod_qty". You can handle it like this: new Text(cart_prod_qty != null ? cart_prod_qty.toString : '')
The error itself shows what's wrong in the code, Text widget works only with string and for null they intentionally have thrown an exception. Check text.dart file implementation where they added throwing an exception.
assert(
data != null,
'A non-null String must be provided to a Text widget.',
),
To solve above error you have to provide some default text.
new Text(cart_prod_qty!=null?cart_prod_qty:'Default Value'),
This looks like a problem with null
value. In Text(cart_prod_qty)
, you're providing null to a Text widget, which is not allowed. in Text widget The data parameter must not be null.
The solution Do not pass null
to Text
widgets. To avoid it set a default value or Check the values you are receiving is not null. when calling the Text()
widgets
You can assign a default value and could change that to follow:
Text(cart_prod_qty ?? 'default value').
If you have a dart model or collection type then check null value and pass a default value like this
ListTile(
title: Text(User[‘user_name’] ?? 'default'),
subtitle: Text(User[‘user’_info] ?? 'default'),
);