Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStoreBase=GRADLE_USER_HOME
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,17 @@ class InAppUpdatePlugin : FlutterPlugin, MethodCallHandler,
private var appUpdateInfo: AppUpdateInfo? = null
private var appUpdateManager: AppUpdateManager? = null

private var flexibleUpdateProgress: Long = 0L
private var flexibleUpdateSize: Long = 0L

override fun onMethodCall(call: MethodCall, result: Result) {
when (call.method) {
"checkForUpdate" -> checkForUpdate(result)
"performImmediateUpdate" -> performImmediateUpdate(result)
"startFlexibleUpdate" -> startFlexibleUpdate(result)
"completeFlexibleUpdate" -> completeFlexibleUpdate(result)
"flexibleUpdateProgress" -> getFlexibleUpdateProgress(result)
"flexibleUpdateSize" -> getFlexibleUpdateSize(result)
else -> result.notImplemented()
}
}
Expand Down Expand Up @@ -227,7 +232,14 @@ class InAppUpdatePlugin : FlutterPlugin, MethodCallHandler,

appUpdateManager?.registerListener { state ->
addState(state.installStatus())
if (state.installStatus() == InstallStatus.DOWNLOADED) {
if (state.installStatus() == InstallStatus.DOWNLOADING) {
val bytesDownloaded = state.bytesDownloaded()
val totalBytesToDownload = state.totalBytesToDownload()
flexibleUpdateSize = totalBytesToDownload
flexibleUpdateProgress = (bytesDownloaded * 100) / totalBytesToDownload
// Show update progress bar.
} else if (state.installStatus() == InstallStatus.DOWNLOADED) {
flexibleUpdateProgress = 100
updateResult?.success(null)
updateResult = null
} else if (state.installErrorCode() != InstallErrorCode.NO_ERROR) {
Expand All @@ -241,6 +253,14 @@ class InAppUpdatePlugin : FlutterPlugin, MethodCallHandler,
}
}

private fun getFlexibleUpdateProgress(result: Result) = checkAppState(result) {
result.success(flexibleUpdateProgress)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a stream would be nicer, but this should be good enough - thanks! Will merge soon

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, any timeline around merging this?

}

private fun getFlexibleUpdateSize(result: Result) = checkAppState(result) {
result.success(flexibleUpdateSize)
}

private fun completeFlexibleUpdate(result: Result) = checkAppState(result) {
appUpdateManager?.completeUpdate()
}
Expand Down
10 changes: 10 additions & 0 deletions lib/in_app_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ class InAppUpdate {
}
}

// App update progress in percentage (0 - 100)
static Future<int> getFlexibleUpdateProgress() async {
return await _channel.invokeMethod('flexibleUpdateProgress');
}

// App update size in bytes
static Future<int> getFlexibleUpdateSize() async {
return await _channel.invokeMethod('flexibleUpdateSize');
}

/// Installs the update downloaded via [startFlexibleUpdate].
///
/// [startFlexibleUpdate] has to be completed successfully.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ packages:
version: "0.1.4-beta"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=1.20.0"
flutter: ">=1.20.0"