Flutter 如何为水平列表中的每个框添加按钮?
我找不到一种方法来为每个图标添加一个按钮,它们只是显示出来,但它们没有任何类型的操作来导航到另一个页面。 这是我的代码,可能我要求的很简单,我提前道歉 如果你需要我给你发送一些其他类型的文件,我没有问题 控件上部(){Flutter 如何为水平列表中的每个框添加按钮?,flutter,dart,Flutter,Dart,我找不到一种方法来为每个图标添加一个按钮,它们只是显示出来,但它们没有任何类型的操作来导航到另一个页面。 这是我的代码,可能我要求的很简单,我提前道歉 如果你需要我给你发送一些其他类型的文件,我没有问题 控件上部(){ 返回堆栈( 儿童:[ 克利帕斯( 裁剪器:UpperClipper(), 子:容器( 高度:尺寸。getWidthPx(240), 装饰:盒子装饰( 梯度:线性梯度( 颜色:[颜色曲线,颜色曲线辅助], ), ), ), ), 纵队( 儿童:[ 容器( 填充:仅限边集(顶部:si
返回堆栈(
儿童:[
克利帕斯(
裁剪器:UpperClipper(),
子:容器(
高度:尺寸。getWidthPx(240),
装饰:盒子装饰(
梯度:线性梯度(
颜色:[颜色曲线,颜色曲线辅助],
),
),
),
),
纵队(
儿童:[
容器(
填充:仅限边集(顶部:size.getWidthPx(36)),
子:列(
儿童:[
titleWidget(),
SizedBox(高度:size.getWidthPx(10)),
upperBoxCard(),
],
),
),
左对齐文本(
正文:“Cercanos a ti”,
leftPadding:size.getWidthPx(16),
textColor:textPrimaryColor,
字体大小:16.0),
水平仪(
儿童:[
对于(int i=0;i
您可以这样做:
HorizontalList(
children: premiumList.map((item) => propertyCard(item)).toList(),
)
这就是你要的声明 卡片属性卡片(属性){ 回程卡(
标高:4.0,
保证金:全部(8),
形状:RoundedRectangleBorder(borderRadius:borderRadius.circular(12)),
边界前景:对,
子:容器(
高度:尺寸。getWidthPx(150),
宽度:大小。getWidthPx(170),
子:列(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
ClipRRect(
borderRadius:仅限borderRadius(
左上:半径。圆形(12.0),
右上角:半径。圆形(12.0)),
子项:Image.asset('assets/${property.Image}',
适合:BoxFit.fill),
SizedBox(高度:size.getWidthPx(8)),
左对齐文本(
文本:property.propertyName,
leftPadding:size.getWidthPx(8),
textColor:colorCurve,
字体大小:14.0),
左对齐文本(
文本:property.propertyLocation,
leftPadding:size.getWidthPx(8),
textColor:Colors.black,
字体大小:14.0),
SizedBox(高度:size.getWidthPx(4)),
左对齐文本(
文本:property.propertyPrice,
leftPadding:size.getWidthPx(8),
textColor:colorCurve,
字体大小:14.0,
fontWeight:fontWeight.w800),
],
)));
}如果您的
premiumList
是某事物的列表
,请参见List.map
和Iterable.toList
方法来实现该行,它不使用按钮的功能。我需要的是列表中出现的每个实例都具有按钮的功能我看不到prope的实现rtyCard()所以我不能帮你。它应该有按钮。这是你要求的声明。嗯,它没有按钮。你应该在那里添加一个按钮。。
HorizontalList(
children: premiumList.map((item) => propertyCard(item)).toList(),
)
elevation: 4.0,
margin: EdgeInsets.all(8),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
borderOnForeground: true,
child: Container(
height: size.getWidthPx(150),
width: size.getWidthPx(170),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12.0),
topRight: Radius.circular(12.0)),
child: Image.asset('assets/${property.image}',
fit: BoxFit.fill)),
SizedBox(height: size.getWidthPx(8)),
leftAlignText(
text: property.propertyName,
leftPadding: size.getWidthPx(8),
textColor: colorCurve,
fontSize: 14.0),
leftAlignText(
text: property.propertyLocation,
leftPadding: size.getWidthPx(8),
textColor: Colors.black,
fontSize: 14.0),
SizedBox(height: size.getWidthPx(4)),
leftAlignText(
text: property.propertyPrice,
leftPadding: size.getWidthPx(8),
textColor: colorCurve,
fontSize: 14.0,
fontWeight: FontWeight.w800),
],
)));