showOptionalUpdateAlertDialog method
void
showOptionalUpdateAlertDialog({
- required BuildContext context,
- required AppVersionStatus appVersionStatus,
- String alertTitle = 'Update Available',
- String? alertText,
- String updateBtn = 'Update',
- bool allowDismissible = true,
- String dismissBtn = 'Later',
- VoidCallback? dismissAction,
Implementation
void showOptionalUpdateAlertDialog(
{required BuildContext context,
required AppVersionStatus appVersionStatus,
String alertTitle = 'Update Available',
String? alertText,
String updateBtn = 'Update',
bool allowDismissible = true,
String dismissBtn = 'Later',
VoidCallback? dismissAction}) async {
final alertTitleWidget = Text(alertTitle);
final alertTextWidget = Text(
alertText ??
'You can now update this app from ${appVersionStatus.currentVersion} to ${appVersionStatus.storeVersion} version',
);
final updateBtnTxtWidget = Text(updateBtn);
final updateAction = () {
_launchAppStore(appVersionStatus.appStoreLink);
if (allowDismissible) {
Navigator.of(context, rootNavigator: true).pop();
}
};
List<Widget> actions = [
Platform.isAndroid
? TextButton(
child: updateBtnTxtWidget,
onPressed: updateAction,
)
: CupertinoDialogAction(
child: updateBtnTxtWidget,
onPressed: updateAction,
),
];
if (allowDismissible) {
final dismissButtonTextWidget = Text(dismissBtn);
dismissAction = dismissAction ??
() => Navigator.of(context, rootNavigator: true).pop();
actions.add(
Platform.isAndroid
? TextButton(
child: dismissButtonTextWidget,
onPressed: dismissAction,
)
: CupertinoDialogAction(
child: dismissButtonTextWidget,
onPressed: dismissAction,
),
);
}
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));
},
);
}