showNewVersionContent static method
Future<void>
showNewVersionContent({
- required BuildContext context,
- required VersionInfo versionInfo,
- required String appName,
- required String iOSAppId,
- required String defaultUrl,
- String? snapStoreId,
- String? windowsPath,
- String? githubRepositoryName,
- String? githubBranchName,
Implementation
static Future<void> showNewVersionContent({
required BuildContext context,
required VersionInfo versionInfo,
required String appName,
required String iOSAppId,
required String defaultUrl,
String? snapStoreId,
String? windowsPath,
String? githubRepositoryName,
String? githubBranchName,
}) async {
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
final ApLocalizations app = ApLocalizations.current;
final int versionDiff =
versionInfo.code - int.parse(packageInfo.buildNumber);
final String versionName = 'v${versionInfo.code ~/ 10000}.'
'${versionInfo.code % 1000 ~/ 100}.'
'${versionInfo.code % 100}';
String url = '';
if (Platform.isAndroid) {
url = 'market://details?id=${packageInfo.packageName}';
} else if (Platform.isIOS || Platform.isMacOS) {
url = 'itms-apps://itunes.apple.com/tw/app/apple-store/$iOSAppId?mt=8';
} else if (Platform.isLinux && snapStoreId != null) {
url = 'https://snapcraft.io/$snapStoreId';
} else if (Platform.isWindows && windowsPath != null) {
url = sprintf(
windowsPath,
<String>[
versionName,
],
);
} else {
url = defaultUrl;
}
if (githubRepositoryName != null) {
// ignore: always_specify_types
final Response response = await Dio().get(
sprintf(
'https://raw.githubusercontent.com/%s/%s/changelog.json',
<String>[
githubRepositoryName,
githubBranchName ?? 'master',
],
),
options: Options(responseType: ResponseType.plain),
);
final dynamic json = jsonDecode(response.data as String);
//ignore: avoid_dynamic_calls
versionInfo.content = json['${versionInfo.code}'][app.locale] as String;
}
final String versionContent = '${'\n$versionName\n'}${versionInfo.content}';
final String updateContent = sprintf(
app.updateContent,
<String>[
appName,
],
);
final RichText contentWidget = RichText(
textAlign: TextAlign.center,
text: TextSpan(
style: TextStyle(
//ignore: use_build_context_synchronously
color: ApTheme.of(context).grey,
height: 1.3,
fontSize: 16.0,
),
children: <TextSpan>[
TextSpan(
text: '$updateContent\n'
'${versionContent.replaceAll('\\n', '\n')}',
style: const TextStyle(fontWeight: FontWeight.bold),
),
],
),
);
if (versionDiff > 0) {
if (versionInfo.isForceUpdate) {
//ignore: use_build_context_synchronously
if (!context.mounted) return;
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) => PopScope(
canPop: false,
child: DefaultDialog(
title: app.updateTitle,
actionText: app.update,
contentWidget: contentWidget,
actionFunction: () => ApUtils.launchUrl(url),
),
),
);
} else {
//ignore: use_build_context_synchronously
if (!context.mounted) return;
showDialog(
context: context,
builder: (BuildContext context) => YesNoDialog(
title: app.updateTitle,
contentWidget: contentWidget,
leftActionText: app.skip,
rightActionText: app.update,
rightActionFunction: () => ApUtils.launchUrl(url),
),
);
}
}
}