fix:app检测更新补充逻辑

This commit is contained in:
jingyun committed 2026-09-07 11:03:05 +08:00
1 parent 05e89b80bb
commit b4343ea528
5 files changed
+260 -56

No files matched your search

@@ -0,0 +1,43 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_app_update/flutter_app_update.dart';
import 'package:flutter_app_update/result_model.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
final updateProgressProvider = StateProvider<double?>((_) => null);
final updateUrlProvider = StateProvider<String?>((_) => null);
final updateDialogVisibleProvider = StateProvider<bool>((_) => false);
bool _listenerRegistered = false;
/// The native download callback can outlive the update dialog, so it uses the
/// app's provider container instead of retaining a dialog WidgetRef.
void ensureUpdateProgressListener(BuildContext context) {
if (_listenerRegistered) return;
_listenerRegistered = true;
final container = ProviderScope.containerOf(context, listen: false);
AzhonAppUpdate.listener((result) => applyUpdateProgress(container, result));
}
@visibleForTesting
void applyUpdateProgress(ProviderContainer container, ResultModel result) {
switch (result.type) {
case ResultType.downloading:
if (result.progress == null || result.max == null || result.max == 0) {
container.read(updateProgressProvider.notifier).state = null;
break;
}
container.read(updateProgressProvider.notifier).state =
result.progress!.toDouble() / result.max!.toDouble();
break;
case ResultType.done:
container.read(updateProgressProvider.notifier).state = 1;
container.read(updateUrlProvider.notifier).state = result.apk;
break;
case ResultType.error:
case ResultType.cancel:
container.read(updateProgressProvider.notifier).state = null;
break;
default:
break;
}
}