- 上游: github.com/OpenIMSDK/openim-flutter-demo tag 3.8.3-patch.3 commit b3dfdb1e8aaeaaf6f0793e10cadd20d5c184a31f - 并行目录 mobile-next/ 原样导入(含 LICENSE),不覆盖现网 mobile/ - 锁定 Flutter 3.24.5 / Dart 3.5.4 / JDK 17 / Gradle 7.6.3 / AGP 7.3.1 - 实测 Android debug 与 release 构建均成功(见 docs/mobile-next-baseline-import.md) - 本提交可单独回退:git revert 1db1229(重写前) Co-authored-by: multica-agent <github@multica.ai>
133 lines
3.9 KiB
Dart
133 lines
3.9 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:openim_common/openim_common.dart';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
import 'package:rxdart/rxdart.dart';
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
|
|
|
import '../widgets/upgrade_view.dart';
|
|
|
|
mixin UpgradeManger {
|
|
PackageInfo? packageInfo;
|
|
UpgradeInfoV2? upgradeInfoV2;
|
|
var isShowUpgradeDialog = false;
|
|
var isNowIgnoreUpdate = false;
|
|
final subject = PublishSubject<double>();
|
|
final notificationService = NotificationService();
|
|
|
|
void closeSubject() {
|
|
subject.close();
|
|
}
|
|
|
|
void ignoreUpdate() {
|
|
DataSp.putIgnoreVersion(upgradeInfoV2!.buildVersion! + upgradeInfoV2!.buildVersionNo!);
|
|
Get.back();
|
|
}
|
|
|
|
void laterUpdate() {
|
|
isNowIgnoreUpdate = true;
|
|
Get.back();
|
|
}
|
|
|
|
getAppInfo() async {
|
|
packageInfo ??= await PackageInfo.fromPlatform();
|
|
}
|
|
|
|
void nowUpdate() async {
|
|
final appUrl = upgradeInfoV2?.appURl;
|
|
|
|
if (appUrl != null && await canLaunchUrlString(appUrl)) {
|
|
launchUrlString(appUrl);
|
|
return;
|
|
}
|
|
}
|
|
|
|
void checkUpdate() async {
|
|
LoadingView.singleton.wrap(asyncFunction: () async {
|
|
await getAppInfo();
|
|
return Apis.checkUpgradeV2();
|
|
}).then((value) {
|
|
upgradeInfoV2 = value;
|
|
if (!canUpdate) {
|
|
IMViews.showToast('已是最新版本');
|
|
return;
|
|
}
|
|
Get.dialog(
|
|
UpgradeViewV2(
|
|
upgradeInfo: upgradeInfoV2!,
|
|
packageInfo: packageInfo!,
|
|
onNow: nowUpdate,
|
|
subject: subject,
|
|
),
|
|
routeSettings: const RouteSettings(name: 'upgrade_dialog'),
|
|
);
|
|
});
|
|
}
|
|
|
|
autoCheckVersionUpgrade() async {
|
|
if (isShowUpgradeDialog || isNowIgnoreUpdate) return;
|
|
await getAppInfo();
|
|
upgradeInfoV2 = await Apis.checkUpgradeV2();
|
|
|
|
if (!canUpdate) return;
|
|
isShowUpgradeDialog = true;
|
|
Get.dialog(
|
|
UpgradeViewV2(
|
|
upgradeInfo: upgradeInfoV2!,
|
|
packageInfo: packageInfo!,
|
|
onLater: laterUpdate,
|
|
onIgnore: ignoreUpdate,
|
|
onNow: nowUpdate,
|
|
subject: subject,
|
|
),
|
|
routeSettings: const RouteSettings(name: 'upgrade_dialog'),
|
|
).whenComplete(() => isShowUpgradeDialog = false);
|
|
}
|
|
|
|
bool get canUpdate =>
|
|
packageInfo!.version + packageInfo!.buildNumber != upgradeInfoV2!.buildVersion! + upgradeInfoV2!.buildVersionNo!;
|
|
}
|
|
|
|
class NotificationService {
|
|
static final NotificationService _notificationService = NotificationService._internal();
|
|
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
|
final AndroidInitializationSettings _androidInitializationSettings =
|
|
const AndroidInitializationSettings('@mipmap/ic_launcher');
|
|
|
|
factory NotificationService() {
|
|
return _notificationService;
|
|
}
|
|
|
|
NotificationService._internal() {
|
|
if (Platform.isAndroid) {
|
|
init();
|
|
}
|
|
}
|
|
|
|
void init() async {
|
|
final InitializationSettings initializationSettings = InitializationSettings(
|
|
android: _androidInitializationSettings,
|
|
);
|
|
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
|
}
|
|
|
|
Future createNotification(int count, int i, int id, String status) async {
|
|
var androidPlatformChannelSpecifics = AndroidNotificationDetails('progress channel', 'progress channel',
|
|
channelDescription: 'progress channel description',
|
|
channelShowBadge: false,
|
|
importance: Importance.max,
|
|
priority: Priority.high,
|
|
onlyAlertOnce: true,
|
|
showProgress: true,
|
|
maxProgress: count,
|
|
progress: i);
|
|
var platformChannelSpecifics = NotificationDetails(android: androidPlatformChannelSpecifics);
|
|
await _flutterLocalNotificationsPlugin.show(id, status, '$i%', platformChannelSpecifics, payload: 'item x');
|
|
|
|
return;
|
|
}
|
|
}
|