show static method
Future
show({
- required BuildContext context,
- required AppUpdateData appUpdateData,
- required void onClickUpdate(),
- required void onClickReminder(),
- required void onClickIgnore(),
Implementation
static Future show({
required BuildContext context,
required AppUpdateData appUpdateData,
required void Function() onClickUpdate,
required void Function() onClickReminder,
required void Function() onClickIgnore,
}) {
AlertDialog child;
final isDarkMode =
MediaQuery.of(context).platformBrightness == Brightness.dark;
bool isBackPress = false;
if (appUpdateData.alertType == 0) {
/// Apptics Native Alert
List<Widget> widgetList = <Widget>[];
final updateTextButton = TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: Text(appUpdateData.updateNowText.toUpperCase()),
onPressed: () {
onClickUpdate();
Navigator.of(context).pop();
},
);
final remindMeTextButton = TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: Text(appUpdateData.remindMeLaterText.toUpperCase()),
onPressed: () {
onClickReminder();
Navigator.of(context).pop();
},
);
final ignoreTextButton = TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: Text(appUpdateData.neverAgainText.toUpperCase()),
onPressed: () {
onClickIgnore();
Navigator.of(context).pop();
},
);
widgetList.add(updateTextButton);
if (appUpdateData.option == "1") {
widgetList.add(remindMeTextButton);
widgetList.add(ignoreTextButton);
isBackPress = true;
} else if (appUpdateData.option == "2") {
widgetList.add(remindMeTextButton);
}
child = AlertDialog(
title: Text(appUpdateData.featureTitle,
style: isDarkMode
? const TextStyle(color: Colors.white)
: const TextStyle(color: Colors.black)),
backgroundColor: isDarkMode ? Colors.black : Colors.white,
content: Text(appUpdateData.features),
contentTextStyle: isDarkMode
? const TextStyle(color: Colors.white)
: const TextStyle(color: Colors.black),
actions: widgetList,
);
} else if (appUpdateData.alertType == 1) {
/// Apptics Custom Alert
child = AlertDialog(
contentPadding: const EdgeInsets.all(0),
backgroundColor: isDarkMode ? Colors.black : Colors.white,
contentTextStyle: isDarkMode
? const TextStyle(color: Colors.white)
: const TextStyle(color: Colors.black),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
content: buildPopUp(context, appUpdateData, isDarkMode, () {
onClickUpdate();
}, () {
onClickReminder();
}, () {
onClickIgnore();
}, (bool isBack) {
isBackPress = isBack;
}),
);
} else if (appUpdateData.alertType == 2) {
// Android play store app update
child = AlertDialog(
contentPadding: const EdgeInsets.all(0),
backgroundColor: isDarkMode ? Colors.black : Colors.white,
contentTextStyle: isDarkMode
? const TextStyle(color: Colors.white)
: const TextStyle(color: Colors.black),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
content: buildPopUp(context, appUpdateData, isDarkMode, () {
onClickUpdate();
}, () {
onClickReminder();
}, () {
onClickIgnore();
}, (bool isBack) {
isBackPress = isBack;
}),
);
} else {
child = AlertDialog(content: Container());
}
return showDialog(
context: context,
barrierDismissible: false,
useRootNavigator: false,
builder: (context) {
return WillPopScope(
child: child,
onWillPop: () async {
if (isBackPress) {
onClickIgnore();
} else {
SystemNavigator.pop();
}
return isBackPress;
});
});
}