【发布时间】:2020-09-30 03:28:59
【问题描述】:
当我使用 .builder() 方法实现 ListView 类时,我的应用程序中断并且不会在该页面上显示任何内容。
这是我实现 ListView 的方式
Column(children: <Widget>[
ListView.builder(
itemCount: profileListItems.length,
itemBuilder: (BuildContext context, int index) {
ProfileListItem profileListItem = profileListItems[index];
return InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
children: <Widget>[
Stack(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(28.0),
child: Container(
height: 50.0,
width: 50.0,
color: Theme.of(context).primaryColor,
child: profileListItem.icon
),
),
],
),
SizedBox(width: 16),
Text(
profileListItem.text,
style: TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold,
fontSize: 16
),
)
],
),
),
);
}
)
])
这是我的 ProfileListItem 类
import 'package:flutter/material.dart';
class ProfileListItem {
Icon icon;
String text;
String navigation;
ProfileListItem({
this.icon,
this.text,
this.navigation,
});
}
List<ProfileListItem> profileListItems = [
ProfileListItem(
icon: Icon(
Icons.dashboard,
color: Colors.white,
size: 24.0,
),
text: 'Dashoard',
navigation: 'Italy',
)
];
当我添加 ListView 类时,页面上的所有其他小部件也会消失。只是一个白屏。
【问题讨论】:
-
您是否收到任何错误消息?
-
因为Column,添加设计图
-
@Jwildsmith 代码中没有错误,运行时没有错误,ios/android 模拟器的屏幕上也没有错误。
-
@Kherel 你这是什么意思?
-
该列似乎没有任何用途,请尝试将其删除并使用 ListView.builder
标签: listview flutter dart builder