I get below error message,
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Positioned wants to apply ParentData of type StackParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.
Usually, this means that the Positioned widget has the wrong ancestor RenderObjectWidget. Typically, Positioned widgets are placed directly inside Stack widgets.
The offending Positioned is currently placed inside a ColorFiltered widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Semantics ← VectorGraphic ← SvgPicture ← Positioned ← ColorFiltered ← Align ← Stack ← Align ← SizedBox ← TopRanking ← ⋯
When the exception was thrown, this was the stack
Mostly I get this error message when I use Expanded not in Row or Column etc.
However it is not related to Expanded.
Semantics ← VectorGraphic ← SvgPicture ← Positioned ← ColorFiltered ← Align ← Stack ← Align ← SizedBox ← TopRanking ← ⋯
Which Widget throws this error in this root?
class TopRanking extends StatelessWidget {
const TopRanking({super.key});
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return SizedBox(
height: size.height * 0.22,
child: Align(
alignment: Alignment.bottomCenter,
child: Stack(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: size.width * 0.15,
height: size.width * 0.15,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.grey.shade200,
width: 2,
),
),
child: Center(
child: CircleAvatar(
radius: size.width * 0.06,
backgroundColor: Colors.blue,
),
),
),
Gaps.v8,
const Text(
"김진솔",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w800,
fontSize: Sizes.size18,
),
),
Gaps.v4,
Text(
"1000점",
style: TextStyle(
color: Colors.grey.shade600,
fontSize: Sizes.size14,
),
),
],
),
Positioned(
top: size.height * 0.05,
right: size.width * 0.08,
child: Image.asset(
"assets/ranking/silver.png",
width: size.width * 0.09,
),
),
],
),
Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: size.width * 0.2,
height: size.width * 0.2,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.grey.shade200,
width: 2,
),
),
child: Center(
child: CircleAvatar(
radius: size.width * 0.085,
backgroundColor: Colors.amber,
),
),
),
Gaps.v8,
const Text(
"허이랑",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w800,
fontSize: Sizes.size18,
),
),
Gaps.v4,
Text(
"2000점",
style: TextStyle(
color: Colors.grey.shade600,
fontSize: Sizes.size14,
),
),
],
),
Positioned(
top: -size.height * 0.01,
child: Image.asset(
"assets/ranking/gold.png",
width: size.width * 0.2,
),
),
],
),
Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: size.width * 0.15,
height: size.width * 0.15,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.grey.shade200,
width: 2,
),
),
child: Center(
child: CircleAvatar(
radius: size.width * 0.06,
backgroundColor: Colors.red,
),
),
),
Gaps.v8,
const Text(
"신지원",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w800,
fontSize: Sizes.size18,
),
),
Gaps.v4,
Text(
"800점",
style: TextStyle(
color: Colors.grey.shade600,
fontSize: Sizes.size14,
),
),
],
),
Positioned(
top: size.height * 0.05,
right: size.width * 0.08,
child: Image.asset(
"assets/ranking/bronze.png",
width: size.width * 0.09,
),
),
],
),
],
),
Align(
alignment: Alignment.topRight,
child: ColorFiltered(
colorFilter: const ColorFilter.mode(
Color.fromARGB(100, 92, 7, 228),
BlendMode.srcIn,
),
child: Positioned(
child: SvgPicture.asset(
"assets/svg/more.svg",
width: 27,
height: 27,
),
),
),
)
],
),
),
);
}
}
2
Answers
On your last
Align
widget, you can try removingchild: Positioned
widget. You don’t need to nestAlign(Positioned
widget.In your code, it looks like you want to apply a color filter to an SvgPicture. To achieve this, you can wrap the SvgPicture with a ColorFiltered widget and then place the whole ColorFiltered widget inside the Stack, like this: