Files
eh_downloader_flutter/lib/components/scroll_parent.dart

31 lines
993 B
Dart

import 'package:flutter/material.dart';
class ScrollParent extends StatelessWidget {
final ScrollController controller;
final Widget child;
const ScrollParent({Key? key, required this.controller, required this.child})
: super(key: key);
@override
Widget build(BuildContext context) {
return NotificationListener<OverscrollNotification>(
onNotification: (OverscrollNotification value) {
if (value.overscroll < 0 && controller.offset + value.overscroll <= 0) {
if (controller.offset != 0) controller.jumpTo(0);
return true;
}
if (controller.offset + value.overscroll >=
controller.position.maxScrollExtent) {
if (controller.offset != controller.position.maxScrollExtent)
controller.jumpTo(controller.position.maxScrollExtent);
return true;
}
controller.jumpTo(controller.offset + value.overscroll);
return true;
},
child: child,
);
}
}