showQRCodeDialog method

void showQRCodeDialog(
  1. BuildContext context, {
  2. required String locale,
})

Implementation

void showQRCodeDialog(BuildContext context, {required final String locale}) {
  localization.setLocale(
    locale == "en" ? const Locale('en', 'US') : const Locale('km', 'KH'),
  );
  UDID.createUDID(
    screenName: ScreenName.qrGenerate,
    userID: SecureStorageService.readSecureData(
      SecureStorageService.userId,
    ),
  );
  _qrCodeController.fetchQRCode().then((data) {
    _qrCodeController.qrCodeData.value = data;
  });
  showDialog(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return Dialog(
        backgroundColor: ColorConstant.white,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(12.0),
        ),
        child: SizedBox(
          width: SizeConstant.getHeightWithScreen(291),
          //height: SizeConstant.getHeightWithScreen(400),
          child: Padding(
            padding: EdgeInsets.all(SizeConstant.getHeightWithScreen(24)),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Obx(
                  () => Center(
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Center(
                          child: _qrCodeController.qrCodeData.value.isNotEmpty
                              ? SizedBox(
                                  width:
                                      SizeConstant.getHeightWithScreen(243),
                                  height:
                                      SizeConstant.getHeightWithScreen(208),
                                  child: Container(
                                    color: Colors.transparent,
                                    child: Image.memory(
                                      _qrCodeController.qrCodeData.value,
                                      fit: BoxFit
                                          .cover, // Ensures the image scales properly
                                    ),
                                  ),
                                )
                              : const CircularProgressIndicator(), // Show a loader while fetching
                        ),
                        SizedBox(
                            height: SizeConstant.getHeightWithScreen(10)),
                        Obx(
                          () => _qrCodeController
                                      .qrcode_generate_count.value >
                                  0
                              ? Text(
                                  "${localization.translate("expiresIn")} ${formatTime(_qrCodeController.qrcode_generate_count.value)}",
                                  style: TextStyle(
                                    fontSize: SizeConstant.largeFont,
                                    color: ColorConstant.darkGrey2,
                                    fontWeight: FontWeight.w400,
                                    fontFamily: 'Cellcard',
                                  ),
                                  textAlign: TextAlign.center,
                                )
                              : GestureDetector(
                                  onTap: () {
                                    _qrCodeController
                                        .fetchQRCode()
                                        .then((data) {
                                      _qrCodeController.qrCodeData.value =
                                          data;
                                    });
                                  },
                                  child: Row(
                                    mainAxisSize: MainAxisSize.min,
                                    children: [
                                      SvgPicture.asset(
                                        'assets/images/refresh.svg',
                                        package: Constants.packageName,
                                      ),
                                      SizedBox(
                                          width: SizeConstant
                                              .getHeightWithScreen(2)),
                                      Center(
                                        child: Column(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            crossAxisAlignment:
                                                CrossAxisAlignment.center,
                                            children: [
                                              Text(
                                                localization
                                                    .translate("refresh"),
                                                style: TextStyle(
                                                  fontSize:
                                                      SizeConstant.mediumFont,
                                                  color: ColorConstant
                                                      .paymentBtnColor,
                                                  fontWeight: FontWeight.w400,
                                                  fontFamily: 'Cellcard',
                                                ),
                                                textAlign: TextAlign.center,
                                              ),
                                            ]),
                                      ),
                                    ],
                                  ),
                                ),
                        ),
                        SizedBox(height: SizeConstant.getHeightWithScreen(6)),
                        Text(
                          localization.translate("qrcodeMsg"),
                          textAlign: TextAlign.center,
                          style: TextStyle(
                            fontSize: SizeConstant.mediumFont,
                            color: ColorConstant.darkGrey,
                            fontWeight: FontWeight.w400,
                            fontFamily: 'Cellcard',
                          ),
                        ),
                        SizedBox(
                            height: SizeConstant.getHeightWithScreen(16)),
                        SizedBox(
                          width: double.maxFinite,
                          child: FilledButton(
                            style: FilledButton.styleFrom(
                              padding: EdgeInsets.zero,
                              backgroundColor: ColorConstant.paymentBtnColor,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(8),
                              ),
                            ),
                            onPressed: () {
                              _qrCodeController.stopApiPolling();
                              Navigator.of(context).pop();
                            },
                            child: Text(
                              localization.translate("close"),
                              style: TextStyle(
                                fontSize: SizeConstant.mediumFont,
                                fontWeight: FontWeight.w400,
                                color: ColorConstant.white,
                                fontFamily: 'Cellcard',
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      );
    },
  );
}