import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:sport/widgets/misc.dart';
import 'package:sport/widgets/refresh_header.dart' as loading;

class RequestLoadingWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 100.0,
      // padding: const EdgeInsets.symmetric(vertical: 50.0),
      child: loading.ClassicalHeaderWidget(refreshState: RefreshMode.refresh, pulledExtent: 120.0, refreshTriggerPullDistance: 100.0, refreshIndicatorExtent: 80.0, classicalHeader: buildClassicalHeader(),
      axisDirection: AxisDirection.down,noMore: false, enableInfiniteRefresh: true,),
    );
  }
}

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(
                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,
                      ),
                    ),
                  ],
                )),
          )
        ],
      ),
    );
  }
}
