show method
Future<void>
show({
- int max = 100,
- String msg = "Default Message",
- Completed? completed,
- Cancel? cancel,
- ProgressType progressType = ProgressType.indeterminate,
- ValuePosition valuePosition = ValuePosition.right,
- Color? backgroundColor,
- Color? surfaceTintColor,
- Color? barrierColor,
- Color? progressValueColor,
- Color? progressBgColor,
- TextStyle? valueStyle,
- TextStyle? msgStyle,
- TextAlign msgTextAlign = TextAlign.center,
- int msgMaxLines = 1,
- double elevation = 5.0,
- double borderRadius = 15.0,
- bool barrierDismissible = false,
- bool hideValue = false,
- int closeWithDelay = 100,
- ValueChanged<
DialogStatus> ? onStatusChanged,
Shows the progress dialog with customizable options.
Parameters:
maxMaximum progress value (default: 100). This value determines when the progress is complete.msgMessage to display (default: "Default Message"). Can be updated using update method.completedConfiguration for completion state. Use this to customize completion message, delay, and image. If not provided, dialog will close immediately upon completion.cancelConfiguration for cancel button. Provides options for custom image and click handling.progressTypeType of progress indicator:- indeterminate: Shows spinning indicator
- determinate: Shows actual progress (0-100%)
valuePositionPosition of progress value text (center/right). Only applies whenhideValueis false.backgroundColorDialog background colorsurfaceTintColorDialog surface tint color for Material 3barrierColorColor of the barrier behind the dialogprogressValueColorColor of the progress indicator's fillprogressBgColorBackground color of the progress trackvalueColorColor of the progress value textmsgTextAlignAlignment of the message text (default: center)msgMaxLinesMaximum lines for message text before ellipsis (default: 1)valueStyleText style applied to the progress value textmsgStyleText style applied to themsgtextelevationDialog elevation in logical pixels (default: 5.0)borderRadiusDialog corner radius in logical pixels (default: 15.0)barrierDismissibleWhether clicking outside closes the dialog (default: false)hideValueWhether to hide the progress value text (default: false)closeWithDelayDelay before closing in milliseconds (default: 100) Note: This is ignored ifcompletedis provided.onStatusChangedCallback for dialog status changes (opened/closed/completed)
The dialog can be updated using the update method and closed manually using close.
Status changes can be monitored through the onStatusChanged callback.
Implementation
Future<void> show({
int max = 100,
String msg = "Default Message",
Completed? completed,
Cancel? cancel,
ProgressType progressType = ProgressType.indeterminate,
ValuePosition valuePosition = ValuePosition.right,
Color? backgroundColor,
Color? surfaceTintColor,
Color? barrierColor,
Color? progressValueColor,
Color? progressBgColor,
TextStyle? valueStyle,
TextStyle? msgStyle,
TextAlign msgTextAlign = TextAlign.center,
int msgMaxLines = 1,
double elevation = 5.0,
double borderRadius = 15.0,
bool barrierDismissible = false,
bool hideValue = false,
int closeWithDelay = 100,
ValueChanged<DialogStatus>? onStatusChanged,
}) {
_dialogIsOpen = true;
_msg.value = msg;
_onStatusChanged = onStatusChanged;
_setDialogStatus(DialogStatus.opened);
if (completed?.completedMsgFuture != null) {
completed!.completedMsgFuture!.then((newMsg) {
_completedMsg.value = newMsg;
});
} else if (completed != null) {
_completedMsg.value = completed.completedMsg;
}
return showDialog(
barrierDismissible: barrierDismissible,
barrierColor: barrierColor,
context: _context,
useRootNavigator: _useRootNavigator,
builder: (context) => PopScope(
canPop: barrierDismissible,
child: AlertDialog(
surfaceTintColor: surfaceTintColor,
backgroundColor: backgroundColor,
elevation: elevation,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(borderRadius),
),
),
content: ValueListenableBuilder(
valueListenable: _progress,
builder: (BuildContext context, dynamic value, Widget? child) {
if (value == max) {
_setDialogStatus(DialogStatus.completed);
completed == null
? close(delay: closeWithDelay)
: close(delay: completed.completionDelay);
}
return Column(
mainAxisSize: MainAxisSize.min,
children: [
if (cancel != null) ...[
cancel.autoHidden && value == max
? SizedBox.shrink()
: Align(
alignment: Alignment.topRight,
child: InkWell(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
onTap: () {
close();
if (cancel.cancelClicked != null) {
cancel.cancelClicked!();
}
},
child: Image(
width: cancel.cancelImageSize,
height: cancel.cancelImageSize,
color: cancel.cancelImageColor,
image: cancel.cancelImage ??
AssetImage(
"images/cancel.png",
package: "sn_progress_dialog",
),
),
),
),
],
Row(
children: [
value == max && completed != null
? Image(
width: 40,
height: 40,
image: completed.completedImage ??
AssetImage(
"images/completed.png",
package: "sn_progress_dialog",
),
)
: SizedBox(
width: 35.0,
height: 35.0,
child: progressType.isIndeterminate
? _normalProgress(
bgColor: progressBgColor,
valueColor: progressValueColor,
)
: value == 0
? _normalProgress(
bgColor: progressBgColor,
valueColor: progressValueColor,
)
: _valueProgress(
valueColor: progressValueColor,
bgColor: progressBgColor,
value: (value / max) * 100,
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 15.0,
top: 8.0,
bottom: 8.0,
),
child: ValueListenableBuilder(
valueListenable: _msg,
builder: (BuildContext context, dynamic msgValue,
Widget? child) {
return ValueListenableBuilder(
valueListenable: _completedMsg,
builder: (context, completedMsgValue, child) {
return Text(
value == max && completed != null
? completedMsgValue
: msgValue,
textAlign: msgTextAlign,
maxLines: msgMaxLines,
overflow: TextOverflow.ellipsis,
style: msgStyle,
);
},
);
},
),
),
),
],
),
hideValue == false
? Align(
alignment: valuePosition == ValuePosition.right
? Alignment.bottomRight
: Alignment.bottomCenter,
child: Text(
value <= 0 ? '' : '${_progress.value}/$max',
style: (valueStyle ?? TextStyle(inherit: true))
.copyWith(
decoration: value == max
? TextDecoration.lineThrough
: TextDecoration.none)),
)
: SizedBox.shrink()
],
);
},
),
),
onPopInvokedWithResult: (didPop, result) {
if (didPop) {
_dialogIsOpen = false;
_setDialogStatus(DialogStatus.closed);
}
},
),
);
}