diff --git a/lib/native/installed_apps.dart b/lib/native/installed_apps.dart index b422ed1..0d29901 100644 --- a/lib/native/installed_apps.dart +++ b/lib/native/installed_apps.dart @@ -50,4 +50,18 @@ class AppInfo { 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; } diff --git a/lib/ui/mobile/setting/app_filter.dart b/lib/ui/mobile/setting/app_filter.dart index f82c2a9..3558308 100644 --- a/lib/ui/mobile/setting/app_filter.dart +++ b/lib/ui/mobile/setting/app_filter.dart @@ -75,21 +75,24 @@ class _AppWhitelistState extends State { actions: [ IconButton( icon: const Icon(Icons.add), - onPressed: () { + onPressed: () async { //添加 - Navigator.of(context) - .push(MaterialPageRoute(builder: (context) => const InstalledAppsWidget())) - .then((value) { - if (value != null) { - if (configuration.appWhitelist.contains(value)) { - return; + List list = await Future.wait(appWhitelist); + if (context.mounted) { + Navigator.of(context).push(MaterialPageRoute(builder: (context) { + return InstalledAppsWidget(addedList: list); + })).then((value) { + if (value != null) { + if (configuration.appWhitelist.contains(value)) { + return; + } + setState(() { + configuration.appWhitelist.add(value); + changed = true; + }); } - setState(() { - configuration.appWhitelist.add(value); - changed = true; - }); - } - }); + }); + } }, ), ], @@ -203,22 +206,25 @@ class _AppBlacklistState extends State { actions: [ IconButton( icon: const Icon(Icons.add), - onPressed: () { + onPressed: () async { //添加 - Navigator.of(context) - .push(MaterialPageRoute(builder: (context) => const InstalledAppsWidget())) - .then((value) { - if (value != null) { - if (configuration.appBlacklist?.contains(value) == true) { - return; + List list = await Future.wait(appBlacklist); + if (context.mounted) { + Navigator.of(context) + .push(MaterialPageRoute(builder: (context) => InstalledAppsWidget(addedList: list))) + .then((value) { + if (value != null) { + if (configuration.appBlacklist?.contains(value) == true) { + return; + } + setState(() { + configuration.appBlacklist ??= []; + configuration.appBlacklist?.add(value); + changed = true; + }); } - setState(() { - configuration.appBlacklist ??= []; - configuration.appBlacklist?.add(value); - changed = true; - }); - } - }); + }); + } }, ), ], @@ -267,7 +273,12 @@ class _AppBlacklistState extends State { ///已安装的app列表 class InstalledAppsWidget extends StatefulWidget { - const InstalledAppsWidget({super.key}); + const InstalledAppsWidget({ + super.key, + required this.addedList, + }); + + final List addedList; @override State createState() => _InstalledAppsWidgetState(); @@ -306,6 +317,7 @@ class _InstalledAppsWidgetState extends State { builder: (BuildContext context, AsyncSnapshot> snapshot) { if (snapshot.hasData) { List appInfoList = snapshot.data!; + appInfoList = appInfoList.toSet().difference(widget.addedList.toSet()).toList(); if (keyword != null && keyword!.trim().isNotEmpty) { appInfoList = appInfoList .where((element) =>