request_dialog.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'package:flutter/material.dart';
  2. typedef ApiCall = Future Function();
  3. Future request(BuildContext context, ApiCall api) async {
  4. var start = DateTime.now().millisecondsSinceEpoch;
  5. var pop = false;
  6. showDialog(
  7. barrierDismissible: false,
  8. context: context,
  9. builder: (context) => Dialog(
  10. backgroundColor: Colors.transparent,
  11. elevation: 0,
  12. child: GestureDetector(
  13. onTap: () {
  14. var end = DateTime.now().millisecondsSinceEpoch;
  15. if (end - start > 10 * 1000) {
  16. pop = true;
  17. Navigator.of(context).pop();
  18. }
  19. },
  20. child: Container(
  21. padding: EdgeInsets.all(16.0),
  22. child: Column(
  23. mainAxisSize: MainAxisSize.min,
  24. children: <Widget>[
  25. Container(
  26. width: 100,
  27. height: 100,
  28. decoration: BoxDecoration(
  29. borderRadius: BorderRadius.all(Radius.circular(10.0)),
  30. color: Colors.black45,
  31. ),
  32. child: Padding(
  33. padding: const EdgeInsets.all(20.0),
  34. child: CircularProgressIndicator(),
  35. ),
  36. ),
  37. ],
  38. )),
  39. ))).then((value) {
  40. pop = true;
  41. });
  42. var data = await api.call().catchError((onError) {
  43. print("[onError]:$onError");
  44. });
  45. if (!pop) Navigator.of(context).pop();
  46. return data;
  47. }