diff --git a/lib/providers/database.dart b/lib/providers/database.dart index d4e4c1c..b27397d 100644 --- a/lib/providers/database.dart +++ b/lib/providers/database.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:collection/collection.dart'; +import 'package:drift/drift.dart'; import 'package:fl_clash/common/common.dart'; import 'package:fl_clash/database/database.dart'; import 'package:fl_clash/models/models.dart'; @@ -315,6 +316,15 @@ class ProxyGroups extends _$ProxyGroups with AsyncNotifierMixin { return !proxyGroupsEquality.equals(previous.value, next.value); } + void del(String name) { + database.proxyGroups.remove( + (t) => t.profileId.equals(profileId) & t.name.equals(name), + ); + List newList = List.from(value); + newList = newList.where((item) => item.name != name).toList(); + value = newList; + } + void order(int oldIndex, int newIndex) { if (oldIndex < newIndex) { newIndex -= 1; diff --git a/lib/views/profiles/overwrite/custom_groups.dart b/lib/views/profiles/overwrite/custom_groups.dart index 1af3f0f..783ccdd 100644 --- a/lib/views/profiles/overwrite/custom_groups.dart +++ b/lib/views/profiles/overwrite/custom_groups.dart @@ -563,12 +563,19 @@ class _EditProxyGroupViewState extends ConsumerState<_EditProxyGroupView> { ); } - void _handleDelete() {} + void _handleDelete(int profileId, String name) { + ref.read(proxyGroupsProvider(profileId).notifier).del(name); + final popCb = SheetProvider.of(context)?.nestedNavigatorPopCallback; + if (popCb != null) { + popCb(); + } + } @override Widget build(BuildContext context) { final isBottomSheet = SheetProvider.of(context)?.type == SheetType.bottomSheet; + final profileId = ProfileIdProvider.of(context)!.profileId; final proxyGroup = ref.watch(proxyGroupProvider); return AdaptiveSheetScaffold( sheetTransparentToolBar: true, @@ -628,7 +635,9 @@ class _EditProxyGroupViewState extends ConsumerState<_EditProxyGroupView> { color: context.colorScheme.error, ), ), - onPressed: _handleDelete, + onPressed: () { + _handleDelete(profileId, proxyGroup.name); + }, ), ], ),