Fix Tab destroy error

This commit is contained in:
chen08209
2024-05-06 19:03:49 +08:00
parent 9f89fe8b29
commit fd1dfe5c60
6 changed files with 19 additions and 26 deletions

View File

@@ -236,6 +236,7 @@ class AppController {
}
healthcheck() {
if (globalState.healthcheckLock) return;
for (final delay in appState.delayMap.entries) {
setDelay(
Delay(

View File

@@ -83,12 +83,15 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
groupNames: groupNames,
);
},
builder: (_, state, __) {
if (_tabController != null) {
_tabController!.dispose();
_tabController = null;
shouldRebuild: (prev,next){
if(prev.groupNames.length != next.groupNames.length){
_tabController?.dispose();
_tabController =null;
}
_tabController = TabController(
return prev != next;
},
builder: (_, state, __) {
_tabController ??= TabController(
length: state.groupNames.length,
vsync: this,
initialIndex: state.currentIndex,
@@ -118,7 +121,6 @@ class _ProxiesFragmentState extends State<ProxiesFragment>
children: [
for (final groupName in state.groupNames)
KeepContainer(
key: ObjectKey(groupName),
child: ProxiesTabView(
groupName: groupName,
),

View File

@@ -23,6 +23,7 @@ class GlobalState {
List<Function> updateFunctionLists = [];
List<NavigationItem> currentNavigationItems = [];
bool updatePackagesLock = false;
bool healthcheckLock = false;
startListenUpdate() {
if (timer != null && timer!.isActive == true) return;

View File

@@ -38,12 +38,15 @@ class _ClashMessageContainerState extends State<ClashMessageContainer>
@override
void onDelay(Delay delay) {
context.appController.setDelay(delay);
final appController = context.appController;
appController.setDelay(delay);
globalState.healthcheckLock = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
globalState.updateSortNumDebounce ??= debounce<Function()>(
() {
context.appController.updateGroups();
context.appController.appState.sortNum++;
() async {
await appController.updateGroups();
appController.appState.sortNum++;
globalState.healthcheckLock = false;
},
milliseconds: 5000,
);