internetDialogCheck static method

dynamic internetDialogCheck({
  1. Function? callback,
})

Implementation

static internetDialogCheck({Function? callback}) async {
  var connectivityResult = await (Connectivity().checkConnectivity());
  if (connectivityResult == ConnectivityResult.mobile ||
      connectivityResult == ConnectivityResult.wifi) {
    if (callback != null) {
      callback();
    }
  } else {
    return showDialog(
      barrierDismissible: false,
      context: Get.context!,
      builder: (context) {
        return WillPopScope(
          onWillPop: () async {
            return false;
          },
          child: SimpleDialog(
            insetPadding: EdgeInsets.all(1.h),
            contentPadding: EdgeInsets.all(1.h),
            backgroundColor: Colors.transparent,
            title: Container(
              decoration: const BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(5))),
              child: Column(
                children: [
                  Lottie.asset(
                      "packages/dialog_pp_flutter/assets/dialogs_assets/internet.json",
                      height: 150.h),
                  SizedBox(
                    height: 20.h,
                  ),
                  Text(
                    "Whoops!",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 25.w,
                        fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    height: 10.h,
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 10.w, right: 10.w),
                    child: Text(
                      "There seem to be a problem with your Network Connection",
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: Colors.black38,
                        fontSize: 17.w,
                      ),
                    ),
                  ),
                  SizedBox(
                    height: 20.h,
                  ),
                  InkWell(
                    onTap: () {
                      Get.back();
                      internetDialogCheck(callback: callback);
                    },
                    child: Container(
                      padding: EdgeInsets.symmetric(
                          horizontal: 40.w, vertical: 10.h),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(30),
                          gradient: const LinearGradient(colors: [
                            Color(0xff6ca1ff),
                            Color(0xff5c6fff),
                          ])),
                      child: const Text(
                        "Try Again",
                        style: TextStyle(color: Colors.white),
                      ),
                    ),
                  ),
                  SizedBox(
                    height: 20.h,
                  ),
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}