由于您正在使用水平
ListView
(无宽度限制)和a
Card
默认情况下取最大宽度,您应该限制
width
的
卡片
s
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
body: MyWidget(),
),
),
);
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<Map<String, String>> items = List.generate(10, (index) {
return {
'work_force_name': 'Work Force $index',
'no_work_force': 'x00000$index',
};
}).toList();
return SizedBox(
height: 100,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: items.length,
itemBuilder: (context, index) {
var item = items[index];
return SizedBox(
width: 150,
child: Card(
elevation: 2,
child: ListTile(
dense: true,
title: Text(item['work_force_name'].toString()),
subtitle: Text(item['no_work_force'].toString()),
),
),
);
},
),
);
}
}