I was working on my project and got stucked with this error while using a flexible widget. Check out my code below. I was trying to make the small green box to be flexible and get size according to its need. But it is throwing an error 'Incorrect use of ParentDataWidget'. I think the problem is with Flexible widget I am using. I am not sure kindly help me out. Here is my code.
Product Card Widget.dart
Padding(
padding: const EdgeInsets.only(
top: 10,
left: 5,
),
child: Flexible(
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: product.type == 'Veg'
? Colors.green.withOpacity(0.8)
: Colors.red.withOpacity(0.8),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
product.type,
style: GoogleFonts.acme(
color: Colors.white,
),
),
),
),
),
),
Error
The following assertion was thrown while applying parent data.: Incorrect use of ParentDataWidget.
The ParentDataWidget Flexible(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type BoxParentData.
Usually, this means that the Flexible widget has the wrong ancestor RenderObjectWidget. Typically, Flexible widgets are placed directly inside Flex widgets. The offending Flexible is currently placed inside a Padding widget.