【发布时间】:2020-04-14 12:38:35
【问题描述】:
我正在尝试构建一个应用,其中包含可加载的预订列表。当用户滚动浏览这些预订时,滚动非常不稳定。我已经完成了所有调试、配置文件和发布模式的测试,但滚动不连贯的问题仍然存在。 iOS 和 Android 都是如此。这是我已经尝试过的 -
- 我已经尝试过使用 const AlwaysScrollableScrollPhysics(),
- 我试过使用不带动画和带动画。在这两种情况下都存在不连贯的滚动
- 我已经尝试过 cached.network.image。出现不稳定的滚动。
即使在配置文件模式下,ListView 构建器也需要超过 16 毫秒来构建 ListTile
return ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
itemCount: widget.bookings.length,
scrollDirection: Axis.vertical,
itemBuilder: (context, int index) {
var count = 10;
var animation = Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
parent: animationController,
curve: Interval((1 / count) * index, 1.0,
curve: Curves.fastOutSlowIn)));
animationController.forward();
return BookingListCard(
booking: widget.bookings[index],
bookings: widget.bookings,
animation: animation,
animationController: animationController,
);
},
);
AnimatedBuilder(
animation: animationController,
builder: (BuildContext context, Widget child) {
return FadeTransition(
opacity: animation,
child: new Transform(
transform: new Matrix4.translationValues(
0.0, 50 * (1.0 - animation.value), 0.0),
child: Padding(
padding:
const EdgeInsets.only(left: 0, right: 0, top: 0, bottom: 0),
child: InkWell(
splashColor: Colors.transparent,
onTap: () {
callback();
},
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Card(
color: AppTheme.halfWhite,
elevation: 0,
child: ListTile(
onTap: () {
Navigator.of(context)
.push(_createRoute(booking, booking.id));
},
leading: Container(
width: _size,
height: _size,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(booking.guest.imageUrl),
fit: BoxFit.fill,
),
),
),
title: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
booking.guest.firstName,
style: AppTheme.title,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Text(
'${(DateFormat("E, d MMM").format(DateTime.parse(booking.checkIn))).toUpperCase()} ',
style: AppTheme.caption,
),
Image.asset(
"assets/images/arrow.png",
width: 12,
height: 12,
),
Text(
' ${(DateFormat("E, d MMM").format(DateTime.parse(booking.checkOut))).toUpperCase()}',
style: AppTheme.caption,
)
],
),
Padding(
padding:
const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: DashedDivider(
color: Colors.black.withOpacity(0.6),
dashWidth: 0.1),
),
Text(
'${(booking.status).toUpperCase()}',
style: TextStyle(
color: statusColorFinder(booking.status),
fontFamily: AppTheme.fontName,
fontWeight: FontWeight.bold,
fontSize: 12,
letterSpacing: 0.4,
height: 0.9,
),
),
],
),
// trailing: Icon(Icons.more_vert),
trailing: booking.status == 'Pending' ? MyBullet() : null,
isThreeLine: false,
),
),
),
),
),
),
);
},
);
【问题讨论】:
-
试过官方文档中最简单的
ListView.builder例子?它也会变得波涛汹涌吗? -
官方文档中的例子还是有点混乱
-
所以您只有一个
ListView,仅此而已?没有异步任务,没有隔离等? -
为什么你一次又一次地宣布动画?只需在您的状态类中声明一次并重用变量,而不是一次又一次地定义。
标签: listview flutter flutter-layout flutter-animation flutter-listview