-1

I have a problem in running code. I see this error in line:

Text(product.description,
          style: TextStyle(
              color: Colors.black,
          ),

and Error:

"The following assertion was thrown building DescriptionPage(dirty):
 A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
 Failed assertion: line 285 pos 10: 'data != null'"
mah
  • 11
  • 2
    Does this answer your question? [A non-null String must be provided to a Text widget](https://stackoverflow.com/questions/56351386/a-non-null-string-must-be-provided-to-a-text-widget) – Chrillewoodz Aug 07 '21 at 07:57

3 Answers3

1

If your Text is empty or null try below code

Text(product.description ?? "")
Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
1
Text((product!=null && product.description!=null)?product.description:'',
          style: TextStyle(
              color: Colors.black,
          ),
M Karimi
  • 1,991
  • 1
  • 17
  • 34
0

this problem is due to the product.description. it seems to have null value. use this instead:

Text(product?.description??"default text",
          style: TextStyle(
              color: Colors.black,
          ),
Abbasihsn
  • 2,075
  • 1
  • 7
  • 17
  • product.description should not be empty or null. When it is printed on the console, it is not empty . I want to show the value of product.description in the text widget – mah Aug 08 '21 at 06:42
  • I know what you want, but the variable that you are providing to the TextWidget is null now! it seems that you have changed it somewhere or redefine it with null value! share your complete code, so I can check it out. – Abbasihsn Aug 08 '21 at 06:46