import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

class RequestLoadingWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 50.0),
      child: SpinKitWave(
        color: Theme.of(context).accentColor,
      ),
    );
  }
}

Widget FadeingCircleLoading(BuildContext context, {Color backgroundColor, Function callBack}) {
  return Positioned(
    top: 0,
    left: 0,
    right: 0,
    bottom: 0,
    child: callBack != null
        ? InkWell(
            child: Container(
              color: backgroundColor != null ? backgroundColor : Color.fromRGBO(255, 255, 255, 0.5),
              width: 100,
              height: 150,
              child: SpinKitFadingCircle(
                size: 100.0,
                color: Theme.of(context).accentColor,
              ),
            ),
            onTap: () {
              callBack();
            },
          )
        : Container(
            color: backgroundColor != null ? backgroundColor : Color.fromRGBO(255, 255, 255, 0.5),
            width: 100,
            height: 150,
            child: SpinKitFadingCircle(
              size: 100.0,
              color: Theme.of(context).accentColor,
            ),
          ),
  );
}

class LoadingWidget extends StatelessWidget {
  bool loading = false;
  Widget child;

  LoadingWidget({this.loading = false, @required this.child});

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        bool result = !loading;
        if (result) {
        }
        return result;
      },
      child: Stack(
        alignment: Alignment.center,
        children: <Widget>[
          Center(child: child),
          Offstage(
            offstage: !loading,
            child: Container(
              color: Color(0x80000000),
              child: SpinKitFadingCircle(
                size: 100.0,
                color: Theme.of(context).accentColor,
              ),
            ),
          )
        ],
      ),
    );
  }
}
