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 = Colors.white,
- Color? surfaceTintColor,
- Color barrierColor = Colors.transparent,
- Color progressValueColor = Colors.blueAccent,
- Color progressBgColor = Colors.blueGrey,
- Color valueColor = Colors.black87,
- Color msgColor = Colors.black87,
- TextAlign msgTextAlign = TextAlign.center,
- FontWeight msgFontWeight = FontWeight.bold,
- FontWeight valueFontWeight = FontWeight.normal,
- double valueFontSize = 15.0,
- double msgFontSize = 17.0,
- 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 color (default: Colors.white)surfaceTintColorDialog surface tint color for Material 3barrierColorColor of the barrier behind the dialog (default: transparent)progressValueColorColor of the progress indicator's fill (default: blueAccent)progressBgColorBackground color of the progress track (default: blueGrey)valueColorColor of the progress value text (default: black87)msgColorColor of the message text (default: black87)msgTextAlignAlignment of the message text (default: center)msgFontWeightFont weight of the message (default: bold)valueFontWeightFont weight of the progress value (default: normal)valueFontSizeFont size of the progress value in logical pixels (default: 15.0)msgFontSizeFont size of the message in logical pixels (default: 17.0)msgMaxLinesMaximum lines for message text before ellipsis (default: 1)elevationDialog 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 = Colors.white,
Color? surfaceTintColor,
Color barrierColor = Colors.transparent,
Color progressValueColor = Colors.blueAccent,
Color progressBgColor = Colors.blueGrey,
Color valueColor = Colors.black87,
Color msgColor = Colors.black87,
TextAlign msgTextAlign = TextAlign.center,
FontWeight msgFontWeight = FontWeight.bold,
FontWeight valueFontWeight = FontWeight.normal,
double valueFontSize = 15.0,
double msgFontSize = 17.0,
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",
),
)
: Container(
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: TextStyle(
fontSize: msgFontSize,
color: msgColor,
fontWeight: msgFontWeight,
),
);
},
);
},
),
),
),
],
),
hideValue == false
? Align(
child: Text(
value <= 0 ? '' : '${_progress.value}/$max',
style: TextStyle(
fontSize: valueFontSize,
color: valueColor,
fontWeight: valueFontWeight,
decoration: value == max
? TextDecoration.lineThrough
: TextDecoration.none,
),
),
alignment: valuePosition == ValuePosition.right
? Alignment.bottomRight
: Alignment.bottomCenter,
)
: SizedBox.shrink()
],
);
},
),
),
onPopInvoked: (didPop) {
if (didPop) {
_dialogIsOpen = false;
_setDialogStatus(DialogStatus.closed);
}
},
),
);
}