progress_dialog_null_safe 3.2.0
progress_dialog_null_safe: ^3.2.0 copied to clipboard
A lightweight, null-safe Flutter package for showing customizable progress dialogs with support for dynamic content updates and various styling options.
progress_dialog_null_safe #
A lightweight package to show a progress dialog. You can change the message and progress shown on the dialog while it is open.
This is a revived version of the original package by fayaz07. It was discontinued, but I really liked the package so I am trynna revive it :D I added null safety and updated most of the stuff, making it null safe and usable again :)
Demo #
The dialog follows your app's theme. Each demo shows light mode on the left and dark mode on the right.
Normal dialog
Download dialog
Custom body
How to use #
Add the package:
flutter pub add progress_dialog_null_safe
Import it in your Dart file:
import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
1. Create the dialog #
Create the ProgressDialog once per screen, for example in initState, and keep it in a field:
class _MyScreenState extends State<MyScreen> {
late final ProgressDialog pr;
@override
void initState() {
super.initState();
pr = ProgressDialog(context);
}
// ...
}
Creating it inside build() also works: a ProgressDialog re-created on rebuild can still update and hide the dialog the previous one opened.
By default it is a normal dialog that shows a message. To show the progress of a download or upload, pass type: ProgressDialogType.download. All other parameters are optional:
// Normal dialog
pr = ProgressDialog(
context,
type: ProgressDialogType.normal,
isDismissible: true, // can the back button or a tap outside close it
showLogs: false,
);
// Shows progress, e.g. "50/100" (or "50.5/100")
pr = ProgressDialog(
context,
type: ProgressDialogType.download,
isDismissible: false,
textDirection: TextDirection.rtl, // for right-to-left languages
);
2. Style it (optional) #
pr.style(
message: 'Downloading file...',
borderRadius: 10.0,
backgroundColor: Colors.white,
progressWidget: const CircularProgressIndicator(),
elevation: 10.0,
insetAnimCurve: Curves.easeInOut,
progress: 0.0,
maxProgress: 100.0,
progressTextStyle: const TextStyle(
color: Colors.black,
fontSize: 13.0,
fontWeight: FontWeight.w400,
),
messageTextStyle: const TextStyle(
color: Colors.black,
fontSize: 19.0,
fontWeight: FontWeight.w600,
),
);
All parameters are optional.
style()has no effect while the dialog is showing; useupdate()for that.
Colours you don't set come from your app's theme, so the dialog matches light and dark mode on its own. Colours you pass to style() are used as they are, in both modes.
3. Show it #
await pr.show();
4. Update it while it is showing #
pr.update(
progress: 50.0,
message: 'Please wait...',
progressWidget: Container(
padding: const EdgeInsets.all(8.0),
child: const CircularProgressIndicator(),
),
maxProgress: 100.0,
progressTextStyle: const TextStyle(
color: Colors.black,
fontSize: 13.0,
fontWeight: FontWeight.w400,
),
messageTextStyle: const TextStyle(
color: Colors.black,
fontSize: 19.0,
fontWeight: FontWeight.w600,
),
);
All parameters are optional.
5. Hide it #
await pr.hide();
If you navigate to another screen after hiding the dialog, wait for
hide()to complete first.
Check if the dialog is showing #
final bool isShowing = pr.isShowing();
isShowing() is true from the moment show() is called, so it is safe to guard show() with it:
if (!pr.isShowing()) pr.show();
Use a custom body #
pr = ProgressDialog(
context,
type: ProgressDialogType.normal,
isDismissible: true,
// your body here
customBody: const LinearProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.blueAccent),
backgroundColor: Colors.white,
),
);
Several dialogs #
Each ProgressDialog keeps its own message, progress and style, so dialogs on different screens never affect each other. One screen shows one dialog at a time.
Default configuration #
If you don't style the dialog, this is what you get:
| Attribute | Value |
|---|---|
| Dismissible | true |
| ProgressDialogType | ProgressDialogType.normal |
| BackgroundColor | Your app's dialog colour (from the theme) |
| BorderRadius | RoundedRectangleBorder(radius: 8.0) |
| AnimationCurve | Curves.easeInOut |
| Elevation | 8.0 |
| ProgressWidget | CircularProgressIndicator (app's primary colour) |
| MessageTextStyle | fontSize: 18.0, fontWeight: FontWeight.w600, theme text colour |
| ProgressTextStyle | fontSize: 12.0, fontWeight: FontWeight.w400, theme text colour |
| MaxProgress | 100.0 |
| showLogs | false |
What can be changed, and when #
| Attribute | When creating | With style() |
With update() while showing |
|---|---|---|---|
| Dismissible | Yes | No | No |
| ProgressDialogType | Yes | No | No |
| TextDirection | Yes | No | No |
| CustomBody | Yes | No | No |
| BackgroundColor | No | Yes | No |
| BorderRadius | No | Yes | No |
| AnimationCurve | No | Yes | No |
| Elevation | No | Yes | No |
| Message | No | Yes | Yes |
| Progress | No | Yes | Yes |
| ProgressWidget | No | Yes | Yes |
| MessageTextStyle | No | Yes | Yes |
| ProgressTextStyle | No | Yes | Yes |
| ShowLogs | Yes | No | No |
The old GIF spinner #
Before 3.2.0 the default spinner was a loading GIF. To keep that look:
pr.style(
progressWidget: Image.asset(
'assets/double_ring_loading_io.gif',
package: 'progress_dialog_null_safe',
),
);
The GIF will be removed in 4.0.0. Loading indicator: https://loading.io/
