我在拖动底部工作表时遇到问题。我有一个用于底部工作表的小部件,在其中,我基于高度调用了一个用于读取数据的类。它运作良好。这是小部件中的底部工作表:
onTap: () async {
showModalBottomSheet(
context: context,
isScrollControlled: true,
isDismissible: true,
enableDrag: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
clipBehavior: Clip.antiAliasWithSaveLayer,
builder: (context) {
return StreamBuilder(
stream: controller.stream,
builder: (context, snapshot) => GestureDetector(
onVerticalDragUpdate:
(DragUpdateDetails details) {
position =
MediaQuery.of(context).size.height -
details.globalPosition.dy;
position.isNegative
? Navigator.pop(context)
: setState(() {
controller.add(position);
});
},
behavior: HitTestBehavior.translucent,
child: Container(
height: snapshot.hasData
? snapshot.data as double
: pageWidth * .32,
// width: double.infinity,
child: PlayerCardDialog()),
),);}); },
这是呼叫数据的类:
class PlayerCardDialog extends StatelessWidget {
const PlayerCardDialog({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var pageWidth = MediaQuery.of(context).size.width;
return LayoutBuilder(builder: (context, constraints) {
return loadBottomSheetData(constraints.maxHeight.toInt() , pageWidth);
});
}
Widget loadBottomSheetData(height, pageWidth) {
if (height <= pageWidth * 0.4) {
return PlayerMiniCard();
} else if (height <= pageWidth * 1.1) {
return PlayerPreview();
} else if(height >= pageWidth* 1.1 ){
return PlayerMain();
}else{
return PlayerMiniCard();
}
}
}
我的问题是关于拖动底部工作表。当我摇晃它一次时,它会停留在那里。它不再移动了。
任何人都可以帮助我吗?我认为position
在我的代码中。我把它放在设置状态。