在使用flutter的时候报了这个错误
` ════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type StackParentData. Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets. The offending Expanded is currently placed inside a Stack widget. The ownership chain for the RenderObject that received the incompatible parent data was: ClipRRect ← ImageBuildView ← Expanded ← Stack ← Semantics ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#efd22 ink renderer] ← NotificationListener ← CustomPaint ← ⋯ `
通过提示信息查看应该是Expanded 写在了 Stack 里面导致的
Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
clipBehavior: Clip.antiAlias,
child: Stack(
fit: StackFit.loose,
children: [
Expanded(
flex: 1,
child: ImageBuildView(
radius: 5,
fit: BoxFit.cover,
url:HxUtils.checkUrl(item.logoFile?.miniImageUrl ?? ''),
)),
/// NOTE 角标
Positioned(//...
),
],
),
),
后面查了一下Expanded、Flexible等组件,在“Container、Padding、Stack”组件中使用也会出现。
切记:Expanded、Flexible只在Row、Column组件内,不在其他组件内使用。
新手学习中如有不对的地方欢迎斧正!