我正致力于在 Flutter 中的 Draggable 对象内实现 DraggableScrollableSheet
。但是,当工作表向下滚动然后用户刷卡时,DraggableScrollableSheet
的垂直滚动位置将被重置。有没有办法解决这个问题并保持滚动位置?
我的 DraggableScrollableSheet 代码:
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: Align(
alignment: Alignment.topCenter,
child: Container(
width: MediaQuery.of(context).size.width * 0.95,
height: MediaQuery.of(context).size.height * 0.75,
decoration: (BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16.0)),
image:
DecorationImage(image: NetworkImage(imgUrl), fit: BoxFit.cover),
)),
child: DraggableScrollableSheet(
minChildSize: 0.25,
initialChildSize: 0.25,
maxChildSize: 0.9,
builder: (BuildContext context, ScrollController scrollController) {
return Container(
padding: EdgeInsets.only(left: 16.0, right: 16.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(16.0),
),
boxShadow: [
BoxShadow(
color: Colors.black54,
blurRadius: 3.0,
spreadRadius: 0.0,
offset: Offset(
0.0,
-3.0,
),
)
],
color: Color(0xFF3B5D76),
),
child: MediaQuery.removePadding(
context: context,
removeTop: true,
child: ListView.builder(
controller: scrollController,
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return Column(
children: [
SwipeHelper(),
BusinessHeader(
title: title,
caption: caption,
description: description,
cost: cost,
stars: stars,
),
BusinessBody(
title: title,
about: about,
owners: owners,
products: products),
BottomLine(),
BusinessFooter(
address: address,
phone: phone,
open: open,
),
],
);
},
),
),
);
},
),
),
),
);
}
我的可拖动小部件代码:
Widget buildCard(business) {
SwipeCard currentBusiness = new SwipeCard(
imgUrl: business['imgUrl'],
title: business['title'],
caption: business['caption'],
description: business['description'],
stars: business['stars'],
cost: business['cost'],
about: business['about'],
owners: business['owners'],
products: business['products'],
address: business['address'],
open: business['open'],
phone: business['phone'],
);
return Draggable(
// Creating the swiping animation only horizontally
axis: Axis.horizontal,
child: currentBusiness,
feedback: currentBusiness,
childWhenDragging: Container(),
onDragEnd: (details) => onDragEnd(details, business),
);
}