作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在左上方对齐列表 View 项目,但它在中心对齐它们。我尝试了另一个小部件,它工作正常,但使用listview却没有。
这是我的代码
Container(
height: height * 30,
// color: Colors.grey[400],
alignment: Alignment.topLeft,
child: ListView.builder(
itemBuilder: (context, i) => ReviewItem(
review: book.reviews[i]['review'],
date: book.reviews[i]['date'],
),
itemCount: book.reviews.length,
),
),
这是评论项目
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
timeago.format(DateTime.parse(date)),
style: Theme.of(context).textTheme.headline4.copyWith(
fontSize: width * kFont12Ratio, color: Colors.grey[500]),
),
SizedBox(height: height * 0.5),
Text(review),
Divider(),
],
);
最佳答案
默认情况下,ListView将自动填充列表的可滚动末端,以避免MediaQuery的填充指示部分障碍。换句话说,如果将小部件放置在ListView之前,则应使用MediaQuery.removePadding
小部件(带有removeTop: true
)包装ListView。像这样:
MediaQuery.removePadding(
context: context,
removeTop: true,
child: ListView.builder(...),
);
关于flutter - 如何在左上方对齐 ListView 项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63430733/
我是一名优秀的程序员,十分优秀!