A non-null String must be provided to a Text widget

前端 未结 9 1674
醉酒成梦
醉酒成梦 2021-02-13 20:15

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

9条回答
  •  星月不相逢
    2021-02-13 21:09

    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'),
    );
    

提交回复
热议问题