12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import 'package:flutter/material.dart';
- typedef ApiCall = Future Function();
- Future request(BuildContext context, ApiCall api) async {
- var start = DateTime.now().millisecondsSinceEpoch;
- var pop = false;
- showDialog(
- barrierDismissible: false,
- context: context,
- builder: (context) => Dialog(
- backgroundColor: Colors.transparent,
- elevation: 0,
- child: GestureDetector(
- onTap: () {
- var end = DateTime.now().millisecondsSinceEpoch;
- if (end - start > 10 * 1000) {
- pop = true;
- Navigator.of(context).pop();
- }
- },
- child: Container(
- padding: EdgeInsets.all(16.0),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Container(
- width: 100,
- height: 100,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(10.0)),
- color: Colors.black45,
- ),
- child: Padding(
- padding: const EdgeInsets.all(20.0),
- child: CircularProgressIndicator(),
- ),
- ),
- ],
- )),
- ))).then((value) {
- pop = true;
- });
- var data = await api.call().catchError((onError) {
- print("[onError]:$onError");
- });
- if (!pop) Navigator.of(context).pop();
- return data;
- }
|