show method
ModProgressController
show({
- String? id,
- ModProgressConfig config = const ModProgressConfig(),
- String? title,
- String? subtitle,
- double? initialProgress,
- VoidCallback? onComplete,
- void onError(
- String error
- VoidCallback? onClose,
Shows a progress overlay with the given configuration. Returns a ModProgressController for controlling the progress.
Implementation
ModProgressController show({
String? id,
ModProgressConfig config = const ModProgressConfig(),
String? title,
String? subtitle,
double? initialProgress,
VoidCallback? onComplete,
void Function(String error)? onError,
VoidCallback? onClose,
}) {
final progressId = id ?? 'progress_${_idCounter++}';
// If a progress with this ID already exists, return its controller
if (_activeProgress.containsKey(progressId)) {
final existingController = _activeProgress[progressId]!.controller;
existingController.open(
title: title ?? config.title,
subtitle: subtitle ?? config.subtitle,
initialProgress: initialProgress ?? config.initialProgress,
);
return existingController;
}
// Create new controller
final controller = ModProgressController(id: progressId);
controller.onCompleteCallback = onComplete;
controller.onErrorCallback = onError;
controller.onCloseCallback = () {
_removeProgress(progressId);
onClose?.call();
};
// Open with initial values
controller.open(
title: title ?? config.title,
subtitle: subtitle ?? config.subtitle,
initialProgress: initialProgress ?? config.initialProgress,
);
// Register with GetX
Get.put(controller, tag: progressId);
// Create overlay entry
final overlayEntry = OverlayEntry(
builder: (context) => Material(
type: MaterialType.transparency,
child: ModProgress(
controller: controller,
config: config,
onClose: () => close(progressId),
),
),
);
_activeProgress[progressId] = _ProgressEntry(
controller: controller,
overlayEntry: overlayEntry,
);
// Insert overlay
WidgetsBinding.instance.addPostFrameCallback((_) {
_insertOverlay(overlayEntry);
});
return controller;
}