我有一个奇怪的问题,我的listviewbuilder只构建前3个项目。对于其他项目,它只构建列表,但没有数据。
这是我的数据
import 'package:pinvault/shared/models/banklistmodel.dart';
List bankList = [
BankListModel(
bank: 'ABC Bank',
img: 'https://cdn-icons-png.flaticon.com/512/66/66455.png',
updated: '29 Dec 2022'),
BankListModel(
bank: 'DEF Bank',
img: 'https://cdn-icons-png.flaticon.com/512/66/66455.png',
updated: '22 Nov 2022'),
BankListModel(
bank: '123 Bank',
img: 'https://cdn-icons-png.flaticon.com/512/66/66455.png',
updated: '4 Dec 2022'),
BankListModel(
bank: 'XYZ Bank',
img: 'https://cdn-icons-png.flaticon.com/512/66/66455.png',
updated: '12 Oct 2022'),
];
这是我的模特
class BankListModel {
String img;
String bank;
String updated;
BankListModel({
required this.img,
required this.bank,
required this.updated,
});
}
这是我的列表视图生成器代码
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:pinvault/shared/data/dummydata.dart';
class BankList extends StatelessWidget {
const BankList({super.key});
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: bankList.length,
scrollDirection: Axis.vertical,
shrinkWrap: false,
itemBuilder: (context, index) {
print(index);
return ListTile(
visualDensity: VisualDensity.adaptivePlatformDensity,
tileColor: Colors.grey,
dense: false,
shape: const Border(bottom: BorderSide()),
subtitle: Text('Last Updated On: ${bankList[index].updated}'),
title: Text(
bankList[index].bank,
style: const TextStyle(fontWeight: FontWeight.bold),
),
leading: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Image.network(bankList[index].img,
height: 80, width: 80, fit: BoxFit.contain),
),
);
});
}
}
这是它在屏幕上的样子,你会注意到最后一项没有呈现任何文本或img。
1条答案
按热度按时间mbskvtky1#
请更新
sizebox