Skip to content

Instantly share code, notes, and snippets.

@miguelpruivo
Last active May 7, 2020 13:27
Show Gist options
  • Save miguelpruivo/6ae5f192200426a9c0f40803b62f7e53 to your computer and use it in GitHub Desktop.
Save miguelpruivo/6ae5f192200426a9c0f40803b62f7e53 to your computer and use it in GitHub Desktop.
A way to easily handle status bar taps on custom ScrollController instances. Thanks @Kavantix.
class _ScrollController extends ScrollController {
final attachedPositions = <ScrollPosition>{};
ScrollController _scaffoldScrollController;
void init(BuildContext context) {
_scaffoldScrollController = PrimaryScrollController.of(context);
}
set scaffoldScrollController(ScrollController value) {
if (_scaffoldScrollController != value) {
for (final position in attachedPositions) {
_scaffoldScrollController?.detach(position);
value?.attach(position);
}
}
_scaffoldScrollController = value;
}
@override
void attach(ScrollPosition position) {
super.attach(position);
if (_scaffoldScrollController != null) {
_scaffoldScrollController.attach(position);
attachedPositions.add(position);
}
}
@override
void detach(ScrollPosition position) {
super.detach(position);
if (attachedPositions.contains(position)) {
_scaffoldScrollController?.detach(position);
attachedPositions.remove(position);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment