47 lines
1.3 KiB
Dart
47 lines
1.3 KiB
Dart
import 'dart:io';
|
|
|
|
import '../core/config/app_config.dart';
|
|
import '../core/network/api_client.dart';
|
|
import '../core/network/endpoints.dart';
|
|
|
|
/// 版本检查(《03-接口文档》10.1,《01-开发文档》5.7)
|
|
class VersionService {
|
|
VersionService._();
|
|
|
|
static Future<VersionInfo> check() async {
|
|
final data = await ApiClient.get<Map<String, dynamic>>(
|
|
Endpoints.appVersion,
|
|
queryParameters: {
|
|
'platform': Platform.isIOS ? 'ios' : 'android',
|
|
'version_code': AppConfig.appVersionCode,
|
|
},
|
|
);
|
|
return VersionInfo(
|
|
latestVersion: (data['latest_version'] as String?) ?? '',
|
|
latestVersionCode: (data['latest_version_code'] as num?)?.toInt() ?? 0,
|
|
forceUpdate: (data['force_update'] as bool?) ?? false,
|
|
updateUrl: (data['update_url'] as String?) ?? '',
|
|
notice: (data['notice'] as String?) ?? '',
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 版本检查结果
|
|
class VersionInfo {
|
|
VersionInfo({
|
|
required this.latestVersion,
|
|
required this.latestVersionCode,
|
|
required this.forceUpdate,
|
|
required this.updateUrl,
|
|
required this.notice,
|
|
});
|
|
|
|
final String latestVersion;
|
|
final int latestVersionCode;
|
|
final bool forceUpdate;
|
|
final String updateUrl;
|
|
|
|
/// 维护公告(非空时全 App 只读提示)
|
|
final String notice;
|
|
}
|