因此,我创建了一个自定义列表视图 (list_item.dart),用于保存来自卡片内 api 的数据并将其显示给用户。当我尝试用数据填充我的列表视图时,我收到错误“A RenderFlex右侧溢出 1307 像素。在卡片小部件内“。我尝试将卡片小部件放在灵活的小部件旁边,但它没有用。请帮忙。
class CustomListItem extends StatelessWidget {
final String subtitle;
final String secondaryText;
final String body;
final int index;
final Widget image;
final void Function() onTap;
const CustomListItem({
required this.subtitle,
required this.secondaryText,
required this.body,
required this.index, required this.onTap,
required this.image,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: Card(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
image,
Column(
children: <Widget>[
RichText(
text: TextSpan(
text: subtitle,
recognizer: TapGestureRecognizer()..onTap = onTap,
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
Text(secondaryText)
],
),
],
),
Container(
height: 1.0,
width: MediaQuery.of(context).size.width,
color: Colors.black,
),
Row(
children: <Widget>[Text(body)],
),
],
),
),
),
);
}
}