durationIndicator method
Widget
durationIndicator({
- required Duration duration,
- double height = 3.0,
- Color? color,
- Color? backgroundColor,
- BorderRadius? borderRadius,
- DurationIndicatorDirection direction = DurationIndicatorDirection.leftToRight,
Creates a duration indicator widget for use in custom snackbar builders
This provides a convenient way to add a progress bar to custom snackbars
when using handleDurationTimerManually: true. The indicator shows
the remaining time before the snackbar auto-dismisses.
Example usage with a custom builder:
Modal.showSnackbar(
handleDurationTimerManually: true,
duration: const Duration(seconds: 4),
builder: ([_]) => Column(
mainAxisSize: MainAxisSize.min,
children: [
// Your custom content here
Container(
padding: const EdgeInsets.all(16),
child: Text('Custom snackbar'),
),
// Add the duration indicator at the bottom (or anywhere you want)
Modal.durationIndicator(
duration: const Duration(seconds: 4),
color: Colors.blue,
),
],
),
);
Parameters:
duration: The total duration of the snackbar (required)height: Height of the progress bar (default: 3.0)color: Color of the progress bar (default: amber)backgroundColor: Background track color (default: color with 30% opacity)borderRadius: Border radius for the indicatordirection: Direction of progress animation (leftToRight or rightToLeft)
Implementation
Widget durationIndicator({
required Duration duration,
double height = 3.0,
Color? color,
Color? backgroundColor,
BorderRadius? borderRadius,
DurationIndicatorDirection direction =
DurationIndicatorDirection.leftToRight,
}) {
final effectiveColor = color ?? Colors.amber;
return SnackbarDurationIndicator(
duration: duration,
height: height,
color: effectiveColor,
backgroundColor: backgroundColor ?? effectiveColor.withValues(alpha: 0.3),
borderRadius: borderRadius,
direction: direction,
);
}