promptUpdate method Null safety
This method shows an customizable AlertDialog if an update is available.
Implementation
Future<void> promptUpdate(BuildContext context,
{String title = 'Update Available',
String message = '''
There is an updated version available on the App Store. Would you like to upgrade?''',
String buttonUpgradeText = 'Upgrade',
String buttonCancelText = 'Cancel',
bool forceUpgrade = false}) async {
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (context) {
return FutureBuilder<bool>(
future: updateIsAvailable(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final buttons = <Widget>[];
if (!forceUpgrade) {
buttons.add(TextButton(
child: Text(buttonCancelText),
onPressed: () {
Navigator.of(context).pop();
},
));
}
buttons.add(TextButton(
child: Text(buttonUpgradeText),
onPressed: () async {
final url = _response.url;
if (url != '' && await canLaunch(url)) {
await launch(url, forceSafariVC: false);
}
if (!forceUpgrade) {
Navigator.of(context).pop();
}
},
));
return AlertDialog(
title: Text(title),
content: Text(message),
actions: buttons,
);
}
return Container();
});
},
);
}