1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import 'package:flutter/material.dart';
- import 'package:flutter_spinkit/flutter_spinkit.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,
- child: 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: SpinKitFadingCircle(
- color: Theme.of(context).accentColor,
- ),
- ),
- ],
- )),
- )));
- var data = await api.call().catchError((onError) {
- print("[onError]:$onError");
- });
- if (!pop) Navigator.of(context).pop();
- return data;
- }
|