【发布时间】:2020-10-13 11:09:29
【问题描述】:
我是 Flutter 和 dart 的新手,我想制作一个水平列表,其中包含可以单击的图像,并将它们带到产品页面。我希望从我将用来制作产品页面的 var product_list 中获取产品详细信息。以下代码运行但列表不可见
import 'package:flutter/material.dart';
import 'package:app/pages/product_details.dart';
class Mostpop extends StatelessWidget {
final product_name;
final product_picture;
final product_price;
Mostpop({
this.product_name,
this.product_picture,
this.product_price
});
var product_list = [
{
"name": "The Bundle",
"picture": "images/thumbnails/t1.jpg",
"price": 99,
},
{
"name": "The Bundle",
"picture": "images/thumbnails/t1.jpg",
"price": 99,
},
{
"name": "The Bundle",
"picture": "images/thumbnails/t1.jpg",
"price": 99,
},
{
"name": "The Bundle",
"picture": "images/thumbnails/t1.jpg",
"price": 99,
},
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Horizontal ListView'),
),
body: Container(
padding: EdgeInsets.symmetric(),
height: MediaQuery.of(context).size.height * 0.35,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: product_list.length, itemBuilder: (context, index) {
return Container(
width: MediaQuery.of(context).size.width * 0.6,
child: Card(
color: Colors.blue,
child: Container(
child: Center(child: Image.asset(product_picture,fit: BoxFit.cover,)),
),
),
);
}),
),
);
}
}
【问题讨论】:
-
能否添加问题截图?
标签: flutter user-interface dart flutter-layout