我有一个可以在上下方向滚动的页面视图。我能否使它只能向下滚动,一旦向下滚动就无法向上滚动?我查询了谷歌,但没有找到有用的结果。
更新:
class _ScrollDownOnlyState extends State<ScrollDownOnly> {
bool checkDir = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Down scroll"),
),
body: PageView.builder(
scrollDirection: Axis.vertical,
physics: checkDir ? const NeverScrollableScrollPhysics() : const AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
print("checl $checkDir");
return GestureDetector(
onPanUpdate: (details) {
print(details.delta.dy);
if (details.delta.dy > 0) {
setState(() {
checkDir = true;
});
}
if (details.delta.dy < 0) {
// set your var
setState(() {
checkDir = false;
});
}
},
child: Container(
margin: EdgeInsets.only(top: 20),
color: Colors.pink,
child: Center(
child: Text(
"${index + 1}",
style: TextStyle(color: Colors.white, fontSize: 30),
),
),
),
);
},
itemCount: 50,
),
);
}
}