Last active
May 7, 2020 13:27
-
-
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.
This file contains 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
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