import 'package:flutter/services.dart'; class InstalledApps { static const MethodChannel _methodChannel = MethodChannel('com.proxy/installedApps'); static Future> getInstalledApps(bool withIcon, {String? packageNamePrefix}) { return _methodChannel .invokeListMethod('getInstalledApps', {"withIcon": withIcon, "packageNamePrefix": packageNamePrefix}).then( (value) => value?.map((e) => AppInfo.formJson(e)).toList() ?? []); } static Future getAppInfo(String packageName) async { return _methodChannel .invokeMethod('getAppInfo', {"packageName": packageName}).then((value) => AppInfo.formJson(value!)); } } class AppInfo { String? name; String? packageName; String? versionName; //icon Uint8List? icon; bool? inValid; AppInfo({ this.name, this.packageName, this.versionName, this.icon, this.inValid, }); AppInfo.formJson(Map json) { name = json['name']; packageName = json['packageName']; versionName = json['versionName']; icon = json['icon']; } Map toJson() { final Map data = {}; data['name'] = name; data['packageName'] = packageName; data['versionName'] = versionName; data['icon'] = icon; return data; } @override String toString() { return toJson().toString(); } @override bool operator ==(Object other) { if (identical(this, other)) { return true; } if (other is AppInfo) { return packageName == other.packageName; } return false; } @override int get hashCode => packageName.hashCode; }