flutter_future_progress_dialog 1.0.0
flutter_future_progress_dialog: ^1.0.0 copied to clipboard
Allows to display progress dialog while the Future function is evaluated.
flutter_future_progress_dialog #
Show progress dialog with animation while waiting for Future completion and then return the result of that Future.
Features #

Getting started #
- install the library
flutter pub add flutter_future_progress_dialog
- import the library
import 'package:flutter_future_progress_dialog/flutter_future_progress_dialog.dart';
Usage #
Working example can be found in /example directory.
Here is a short example of `showProgressDialog`` usage.
Call the showProgressDialog inside your function. Pass context and future arguments. Then handle
result.
Future<String> myFuture() async {
await Future.delayed(const Duration(seconds: 2));
return 'my string';
}
Future<void> yourFunction(BuildContext context) async {
final result = await showProgressDialog(
context: context,
future: () => myFuture(),
);
if (!mounted) {
return;
}
if (result.isError) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Text(
'${result.requireError}',
textAlign: TextAlign.center,
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text(
'OK',
),
),
],
);
},
);
return;
}
const result = result.requireValue; // result variable would hold the 'my string' value here
}
Optionally you can pass a builder to have a custom progress dialog
Future<void> buttonCallback({
required BuildContext context,
}) async {
final result = await showProgressDialog(
future: () => myLongRunningTask(),
context: context,
builder: (context) => AlertDialog(
content: Text('I am loading now'),
),
);
return result!;
}