request_dialog.dart 1.5 KB

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