didChangeAppLifecycleState method

  1. @override
void didChangeAppLifecycleState(
  1. AppLifecycleState state
)
override

Called when the system puts the app in the background or returns the app to the foreground.

An example of implementing this method is provided in the class-level documentation for the WidgetsBindingObserver class.

This method exposes notifications from SystemChannels.lifecycle.

See also:

Implementation

@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
  super.didChangeAppLifecycleState(state);
  final tranIds = cachedData.data!.transInfo.tranNo;
  switch (state) {
    case AppLifecycleState.resumed:
      if (wasInBackground && socket.disconnected) {
        wasInBackground = false;
        final checkoutReponse = await fetchDataFromApi(tranIds, referrerId!);
        if (checkoutReponse.data!.transInfo.status == "success") {
          if (checkoutReponse.data!.checkoutPageConfig.displaySuccessPage ==
              true) {
            final tranInfoSuccesss = checkoutReponse.data!.transInfo;
            final billerInfoSuccess = checkoutReponse.data!.biller;
            final checkConfage = checkoutReponse.data!.checkoutPageConfig;

            if (UniversalPlatform.isWeb) {
              debugPrint('============================is Web');
              debugPrint(
                  '============================iss Web ${B24PaymentSdk.storeDarkMode}');
              Navigator.of(context!).pop();
              BottomsheetWeb.show(
                  context!,
                  MainSuccessWebDialog(
                      darkMode: B24PaymentSdk.storeDarkMode!,
                      biller: billerInfoSuccess,
                      transInfo: tranInfoSuccesss));
            } else {
              debugPrint('============================is Mobile');
              Navigator.of(context!).popUntil((route) => route.isFirst);
              Navigator.of(context!).push(
                MaterialPageRoute(
                  builder: (contents) => ScreenSuccess(
                    biller: billerInfoSuccess,
                    transInfo: tranInfoSuccesss,
                    checkoutPageConfig: checkConfage,
                  ),
                ),
              );
            }

            // Navigator.of(context!).popUntil((route) => route.isFirst);
            // Navigator.of(context!).push(
            //   MaterialPageRoute(
            //     builder: (contents) => ScreenSuccess(
            //       biller: billerInfoSuccess,
            //       transInfo: tranInfoSuccesss,
            //       checkoutPageConfig: checkConfage,
            //     ),
            //   ),
            // );
          } else {
            final redirectUrl = checkoutReponse.data!.transInfo.redirectUrl;
            try {
              if (context != null) {
                wasInBackground = false;
                GoRouter.of(context!).go(redirectUrl);
              }
            } catch (e) {
              if (context != null) {
                wasInBackground = false;
                showMessagePopup(context!,
                    bgColor: Color(0XFFFDEDEE),
                    iconColor: Color(0XFFEE4D61),
                    textColor: Color(0XFF131C18),
                    content:
                        translation.getTranslation('merchSuccessNotFond'),
                    icons: Icons.info_rounded);
              }
            }
          }
        }
      }
      break;
    case AppLifecycleState.detached:
    case AppLifecycleState.hidden:
    case AppLifecycleState.paused:
    case AppLifecycleState.inactive:
  }
}