fix: experimental patches stay selected when toggled off (#946)

This commit is contained in:
Aabed Khan 2023-06-23 19:22:23 +05:45 committed by GitHub
parent d051ae576b
commit 716a30bf7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/toast.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_experimental_patches.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
@ -116,7 +117,7 @@ class _PatchItemState extends State<PatchItem> {
value: widget.isSelected,
activeColor: Theme.of(context).colorScheme.primary,
checkColor:
Theme.of(context).colorScheme.secondaryContainer,
Theme.of(context).colorScheme.secondaryContainer,
side: BorderSide(
width: 2.0,
color: Theme.of(context).colorScheme.primary,
@ -127,11 +128,16 @@ class _PatchItemState extends State<PatchItem> {
!widget._managerAPI
.areExperimentalPatchesEnabled()) {
widget.isSelected = false;
widget.toast.showBottom(
'patchItem.unsupportedPatchVersion');
widget.toast
.showBottom('patchItem.unsupportedPatchVersion');
} else {
widget.isSelected = newValue!;
}
if (widget.isUnsupported &&
widget.isSelected &&
!selectedUnsupportedPatches.contains(widget.name)) {
selectedUnsupportedPatches.add(widget.name);
}
});
widget.onChanged(widget.isSelected);
},

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/widgets/I18nText.dart';
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
import 'package:revanced_manager/ui/views/settings/settings_viewmodel.dart';
class SExperimentalPatches extends StatefulWidget {
@ -10,6 +11,7 @@ class SExperimentalPatches extends StatefulWidget {
}
final _settingsViewModel = SettingsViewModel();
final List<String> selectedUnsupportedPatches = [];
class _SExperimentalPatchesState extends State<SExperimentalPatches> {
@override
@ -32,6 +34,12 @@ class _SExperimentalPatchesState extends State<SExperimentalPatches> {
setState(() {
_settingsViewModel.useExperimentalPatches(value);
});
if(!value) {
for (final patch in selectedUnsupportedPatches) {
PatchesSelectorViewModel().selectedPatches.removeWhere((element) => patch == element.name);
}
selectedUnsupportedPatches.clear();
}
},
);
}