showModal function
Implementation
void showModal(ModalEntry modalEntry) {
final context = modalEntry.context;
if (modalEntry.removeOnPop || modalEntry.removeOnPushNext) {
if (modalsRouteObserver.navigator == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('modalsRouteObserver was not set as navigatorObserver'),
ErrorDescription(
'If removeOnPop or removeOnPushNext are used, then modalsRouteObserver must be set.\n'
'For more information please refer to https://api.flutter.dev/flutter/widgets/RouteObserver-class.html',
)
]);
}
}
final overlayState = Overlay.of(context, rootOverlay: true);
final overlayEntry =
OverlayEntry(builder: (BuildContext context) => modalEntry);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_modalsMap.containsKey(modalEntry.tag)) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary(
'There are multiple modal entries that share the same tag'),
ErrorDescription(
'Each ModalEntry must have a unique non-null tag.\n'
'In this case, multiple modal entries had the following tag: ${modalEntry.tag}',
)
]);
}
final above = _modalsMap[modalEntry.aboveTag];
final below = _modalsMap[modalEntry.belowTag];
overlayState!.insert(overlayEntry, above: above, below: below);
_modalsMap.putIfAbsent(modalEntry.tag, () => overlayEntry);
});
}