Last updated:
0 purchases
flutter future progress dialog
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
copied to clipboard
import the library
import 'package:flutter_future_progress_dialog/flutter_future_progress_dialog.dart';
copied to clipboard
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.
Alternatively you can use showCupertinoProgressDialog to show cupertino-styled dialog and showAdaptiveProgressDialog to show dialog matching host OS.
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;
}
switch (result) {
case ResultError(error: final error):
await showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Text(
'$error',
textAlign: TextAlign.center,
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text(
'OK',
),
),
],
);
},
);
case ResultOk<String>(value: final value):
// value variable would hold the 'my string' value here
break;
}
}
copied to clipboard
Optionally you can pass a builder to have a custom progress dialog
Future<Result<LongRunningTaskResult>> buttonCallback({
required BuildContext context,
}) async {
return await showProgressDialog(
future: () => myLongRunningTask(),
context: context,
builder: (context) => AlertDialog(
content: Text('I am loading now'),
),
);
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.