119 lines
2.7 KiB
Dart
119 lines
2.7 KiB
Dart
/// 应用商店信息
|
|
class AppMarketInfo extends Object {
|
|
/// 应用商店
|
|
final AppMarket market;
|
|
|
|
/// 跳转链接(可选,用于网页跳转)
|
|
final String? url;
|
|
|
|
/// 应用包名(可选,用于原生跳转)
|
|
final String? packageName;
|
|
|
|
/// 自定义名称(当 market 为 custom 时使用)
|
|
final String? customName;
|
|
|
|
AppMarketInfo({
|
|
required this.market,
|
|
this.url,
|
|
this.packageName,
|
|
this.customName,
|
|
});
|
|
|
|
/// 从JSON创建
|
|
factory AppMarketInfo.fromJson(Map<String, dynamic> json) {
|
|
return AppMarketInfo(
|
|
market: AppMarket.fromString(json['market']),
|
|
url: json['url'],
|
|
packageName: json['packageName'],
|
|
customName: json['customName'],
|
|
);
|
|
}
|
|
|
|
/// 转换为JSON
|
|
Map<String, dynamic> toJson() => {
|
|
'market': market.name,
|
|
'url': url,
|
|
'packageName': packageName,
|
|
'customName': customName,
|
|
};
|
|
|
|
/// 获取商店名称
|
|
String get marketName {
|
|
if (market == AppMarket.custom && customName != null) {
|
|
return customName!;
|
|
}
|
|
return market.displayName;
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return 'AppMarketInfo{market: $market, url: $url, packageName: $packageName, customName: $customName}';
|
|
}
|
|
}
|
|
|
|
/// 应用商店枚举
|
|
enum AppMarket {
|
|
googlePlay,
|
|
appStore,
|
|
huawei,
|
|
oppo,
|
|
vivo,
|
|
xiaomi,
|
|
tencent,
|
|
coolapk,
|
|
custom,
|
|
unknown;
|
|
|
|
/// 从字符串创建
|
|
static AppMarket fromString(String? market) {
|
|
switch (market?.toLowerCase()) {
|
|
case 'googleplay':
|
|
return AppMarket.googlePlay;
|
|
case 'appstore':
|
|
return AppMarket.appStore;
|
|
case 'huawei':
|
|
return AppMarket.huawei;
|
|
case 'oppo':
|
|
return AppMarket.oppo;
|
|
case 'vivo':
|
|
return AppMarket.vivo;
|
|
case 'xiaomi':
|
|
return AppMarket.xiaomi;
|
|
case 'tencent':
|
|
return AppMarket.tencent;
|
|
case 'coolapk':
|
|
return AppMarket.coolapk;
|
|
case 'custom':
|
|
return AppMarket.custom;
|
|
default:
|
|
return AppMarket.unknown;
|
|
}
|
|
}
|
|
|
|
/// 获取显示名称
|
|
String get displayName {
|
|
switch (this) {
|
|
case AppMarket.googlePlay:
|
|
return 'Google Play';
|
|
case AppMarket.appStore:
|
|
return 'App Store';
|
|
case AppMarket.huawei:
|
|
return '华为应用市场';
|
|
case AppMarket.oppo:
|
|
return 'OPPO软件商店';
|
|
case AppMarket.vivo:
|
|
return 'vivo应用商店';
|
|
case AppMarket.xiaomi:
|
|
return '小米应用商店';
|
|
case AppMarket.tencent:
|
|
return '腾讯应用宝';
|
|
case AppMarket.coolapk:
|
|
return '酷安';
|
|
case AppMarket.custom:
|
|
return '自定义';
|
|
default:
|
|
return '未知';
|
|
}
|
|
}
|
|
}
|