Created
April 2, 2024 12:51
-
-
Save dinko7/c1b5c07cc974eb9cc097bdbbafa7db85 to your computer and use it in GitHub Desktop.
Swipe to refresh on a non-scrollable page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class _ClampingScrollBehavior extends ScrollBehavior { | |
@override | |
ScrollPhysics getScrollPhysics(BuildContext context) => | |
const ClampingScrollPhysics(); | |
} | |
class NonScrollableRefreshIndicator extends StatelessWidget { | |
final Widget child; | |
final Future<void> Function() onRefresh; | |
const NonScrollableRefreshIndicator({ | |
required this.child, | |
required this.onRefresh, | |
super.key, | |
}); | |
@override | |
Widget build(BuildContext context) { | |
return LayoutBuilder( | |
builder: ((_, constraints) { | |
return RefreshIndicator( | |
onRefresh: onRefresh, | |
child: ScrollConfiguration( | |
behavior: _ClampingScrollBehavior(), | |
child: SingleChildScrollView( | |
physics: const AlwaysScrollableScrollPhysics(), | |
child: ConstrainedBox( | |
constraints: BoxConstraints( | |
minHeight: MediaQuery.of(context).size.height, | |
maxHeight: MediaQuery.of(context).size.height, | |
), | |
child: child, | |
), | |
), | |
), | |
); | |
}), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment