upgrade pkg version

This commit is contained in:
kit
2024-09-25 12:02:25 +07:00
parent fc4d61d1b5
commit 5a37945b9c
14 changed files with 290 additions and 132 deletions

View File

@@ -51,7 +51,6 @@ class NativeUpdater {
/// Get current installed version of app
final PackageInfo info = await PackageInfo.fromPlatform();
/// Set singleton properties
_nativeUpdaterInstance._context = context;
_nativeUpdaterInstance._forceUpdate = forceUpdate;
@@ -63,11 +62,14 @@ class NativeUpdater {
_nativeUpdaterInstance._iOSCloseButtonLabel = iOSCloseButtonLabel;
_nativeUpdaterInstance._iOSIgnoreButtonLabel = iOSIgnoreButtonLabel;
_nativeUpdaterInstance._iOSAlertTitle = iOSAlertTitle;
_nativeUpdaterInstance._requireUpdateText = requireUpdateText ?? 'requires that you update to the latest version. You cannot use this app until it is updated.';
_nativeUpdaterInstance._recommendUpdateText = recommendUpdateText ?? 'recommends that you update to the latest version. You can keep using this app while downloading the update.';
_nativeUpdaterInstance._requireUpdateText = requireUpdateText ??
'requires that you update to the latest version. You cannot use this app until it is updated.';
_nativeUpdaterInstance._recommendUpdateText = recommendUpdateText ??
'recommends that you update to the latest version. You can keep using this app while downloading the update.';
_nativeUpdaterInstance._errorText = errorText;
_nativeUpdaterInstance._errorCloseButtonLabel = errorCloseButtonLabel;
_nativeUpdaterInstance._errorSubtitle = errorSubtitle;
/// Show the alert based on current platform
if (Platform.isIOS) {
_nativeUpdaterInstance._showCupertinoAlertDialog();
@@ -81,11 +83,9 @@ class NativeUpdater {
String selectedDefaultDescription;
if (_forceUpdate) {
selectedDefaultDescription =
'$_appName $_requireUpdateText';
selectedDefaultDescription = '$_appName $_requireUpdateText';
} else {
selectedDefaultDescription =
'$_appName $_recommendUpdateText';
selectedDefaultDescription = '$_appName $_recommendUpdateText';
}
Widget alert = UpdateCupertinoAlert(
@@ -113,13 +113,18 @@ class NativeUpdater {
try {
AppUpdateInfo _updateInfo = await InAppUpdate.checkForUpdate();
if (_updateInfo.updateAvailability == UpdateAvailability.updateAvailable) {
if (_updateInfo.updateAvailability ==
UpdateAvailability.updateAvailable) {
if (_forceUpdate == true) {
InAppUpdate.performImmediateUpdate()
.catchError((e) => developer.log(e.toString()));
InAppUpdate.performImmediateUpdate().catchError((e) {
developer.log(e.toString());
return AppUpdateResult.inAppUpdateFailed;
});
} else if (_forceUpdate == false) {
InAppUpdate.startFlexibleUpdate()
.catchError((e) => developer.log(e.toString()));
InAppUpdate.startFlexibleUpdate().catchError((e) {
developer.log(e.toString());
return AppUpdateResult.inAppUpdateFailed;
});
}
}
} on PlatformException catch (e) {
@@ -134,9 +139,9 @@ class NativeUpdater {
builder: (BuildContext context) {
return ErrorMaterialAlert(
appName: _appName,
description:
_errorText ?? 'This version of $_appName was not installed from Google Play Store.',
errorCloseButtonLabel:_errorCloseButtonLabel,
description: _errorText ??
'This version of $_appName was not installed from Google Play Store.',
errorCloseButtonLabel: _errorCloseButtonLabel,
errorSubtitle: _errorSubtitle,
);
},

View File

@@ -1,6 +1,6 @@
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class UpdateCupertinoAlert extends StatelessWidget {
@@ -39,7 +39,7 @@ class UpdateCupertinoAlert extends StatelessWidget {
Widget updateButton = CupertinoDialogAction(
child: Text(updateButtonLabel),
onPressed: () => launch(appStoreUrl),
onPressed: () => launchUrl(Uri(host: appStoreUrl)),
);
return CupertinoAlertDialog(

View File

@@ -14,17 +14,16 @@ class UpdateMaterialAlert extends StatelessWidget {
final String ignoreButtonLabel;
final String newVersionLabel;
UpdateMaterialAlert({
required this.forceUpdate,
required this.appName,
required this.playStoreUrl,
required this.titlePrefix,
required this.description,
required this.updateButtonLabel,
required this.closeButtonLabel,
required this.ignoreButtonLabel,
this.newVersionLabel = 'New version available'
});
UpdateMaterialAlert(
{required this.forceUpdate,
required this.appName,
required this.playStoreUrl,
required this.titlePrefix,
required this.description,
required this.updateButtonLabel,
required this.closeButtonLabel,
required this.ignoreButtonLabel,
this.newVersionLabel = 'New version available'});
@override
Widget build(BuildContext context) {
@@ -47,7 +46,7 @@ class UpdateMaterialAlert extends StatelessWidget {
child: Text(updateButtonLabel.toUpperCase(),
style: TextStyle(color: Colors.white)),
style: flatButtonStyle,
onPressed: () => launch(playStoreUrl),
onPressed: () => launchUrl(Uri(host: playStoreUrl)),
);
return AlertDialog(