showRequiredUpdateAlertDialog method

void showRequiredUpdateAlertDialog({
  1. required BuildContext context,
  2. required AppVersionStatus appVersionStatus,
  3. String alertTitle = 'Update Available',
  4. String? alertText,
  5. String updateBtn = 'Update',
  6. bool allowDismissible = false,
  7. VoidCallback? dismissAction,
})

Implementation

void showRequiredUpdateAlertDialog(
    {required BuildContext context,
    required AppVersionStatus appVersionStatus,
    String alertTitle = 'Update Available',
    String? alertText,
    String updateBtn = 'Update',
    bool allowDismissible = false,
    VoidCallback? dismissAction}) async {
  final alertTitleWidget = Text(alertTitle);
  final alertTextWidget =
      Text(alertText ?? 'Please update the app to continue');

  final updateBtnTxtWidget = Text(updateBtn);
  final updateAction = () {
    _launchAppStore(appVersionStatus.appStoreLink);
  };

  List<Widget> actions = [
    Platform.isAndroid
        ? TextButton(
            child: updateBtnTxtWidget,
            onPressed: updateAction,
          )
        : CupertinoDialogAction(
            child: updateBtnTxtWidget,
            onPressed: updateAction,
          ),
  ];

  showDialog(
    context: context,
    barrierDismissible: allowDismissible,
    builder: (BuildContext context) {
      return WillPopScope(
          child: Platform.isAndroid
              ? AlertDialog(
                  title: alertTitleWidget,
                  content: alertTextWidget,
                  actions: actions,
                )
              : CupertinoAlertDialog(
                  title: alertTitleWidget,
                  content: alertTextWidget,
                  actions: actions,
                ),
          onWillPop: () => Future.value(allowDismissible));
    },
  );
}