showOverlay method
Shows custom Overlay with given Widget
Implementation
void showOverlay({required PositionedBuilder positionedBuilder}) {
assert(_key.currentState?.overlay != null, 'Tried to show overlay but overlayState was null. Key was :$_key');
assert(_defaultFadeInDuration + _defaultFadeInDelay <= _overlayDuration, '''
_defaultFadeInDelay + _defaultFadeDuration must be less than or equal to _overlayDuration''');
final currentOpacity = 0.observable;
Positioned widgetBuilder(BuildContext context) {
final pos = positionedBuilder(context);
return Positioned(
height: pos.height,
width: pos.width,
top: pos.top,
bottom: pos.bottom,
left: pos.left,
right: pos.right,
child: Observer(
builder: (context) => AnimatedOpacity(
opacity: currentOpacity.value.toDouble(),
duration: _defaultFadeInDuration,
child: Material(
child: pos.child,
),
),
),
);
}
final overlayEntry = OverlayEntry(builder: widgetBuilder);
_key.currentState!.overlay!.insert(overlayEntry);
_defaultFadeInDelay.delay(() {
currentOpacity.value = 1;
});
_overlayDuration.delay(() {
overlayEntry
..remove()
..dispose();
});
}