@@ -40,8 +40,10 @@ class ProxiesTabViewState extends ConsumerState<ProxiesTabView>
4040 }
4141 if (! stringListEquality.equals (prev? .a, next.a)) {
4242 _destroyTabController ();
43- final index = next.a.indexWhere ((item) => item == next.b);
44- _updateTabController (next.a.length, index);
43+ final groupNames = next.a;
44+ final currentGroupName = next.b;
45+ final index = groupNames.indexWhere ((item) => item == currentGroupName);
46+ _updateTabController (groupNames.length, index);
4547 }
4648 }, fireImmediately: true );
4749 }
@@ -127,22 +129,22 @@ class ProxiesTabViewState extends ConsumerState<ProxiesTabView>
127129 }
128130
129131 void _tabControllerListener ([int ? index]) {
130- int ? groupIndex = index;
131- if (groupIndex == - 1 ) {
132- return ;
133- }
134- final appController = globalState.appController;
135- if (groupIndex == null ) {
136- final currentIndex = _tabController? .index;
137- groupIndex = currentIndex;
138- }
139- final currentGroups = appController.getCurrentGroups ();
140- if (groupIndex == null || groupIndex > currentGroups.length) {
141- return ;
142- }
143- final currentGroup = currentGroups[groupIndex];
144132 WidgetsBinding .instance.addPostFrameCallback ((_) {
145- globalState.appController.updateCurrentGroupName (currentGroup.name);
133+ int ? groupIndex = index;
134+ if (groupIndex == - 1 ) {
135+ return ;
136+ }
137+ final appController = globalState.appController;
138+ if (groupIndex == null ) {
139+ final currentIndex = _tabController? .index;
140+ groupIndex = currentIndex;
141+ }
142+ final currentGroups = appController.getCurrentGroups ();
143+ if (groupIndex == null || groupIndex > currentGroups.length) {
144+ return ;
145+ }
146+ final currentGroup = currentGroups[groupIndex];
147+ appController.updateCurrentGroupName (currentGroup.name);
146148 });
147149 }
148150
@@ -153,8 +155,8 @@ class ProxiesTabViewState extends ConsumerState<ProxiesTabView>
153155 }
154156
155157 void _updateTabController (int length, int index) {
158+ _destroyTabController ();
156159 if (length == 0 ) {
157- _destroyTabController ();
158160 return ;
159161 }
160162 final realIndex = index == - 1 ? 0 : index;
@@ -170,26 +172,15 @@ class ProxiesTabViewState extends ConsumerState<ProxiesTabView>
170172 @override
171173 Widget build (BuildContext context) {
172174 ref.watch (themeSettingProvider.select ((state) => state.textScale));
173- final state = ref.watch (proxiesTabStateProvider);
175+ final state = ref.watch (proxiesTabStateProvider. select ((state) => state) );
174176 final groups = state.groups;
175- if (groups.isEmpty) {
177+ if (groups.isEmpty || _tabController == null ) {
176178 return NullStatus (
177179 illustration: ProxyEmptyIllustration (),
178180 label: appLocalizations.nullTip (appLocalizations.proxies),
179181 );
180182 }
181- final ProxyGroupViewKeyMap keyMap = {};
182- final children = groups.map ((group) {
183- final key = GlobalObjectKey <_ProxyGroupViewState >(group.name);
184- keyMap[group.name] = key;
185- return ProxyGroupView (
186- key: key,
187- group: group,
188- columns: state.columns,
189- cardType: state.proxyCardType,
190- );
191- }).toList ();
192- _keyMap = keyMap;
183+ _keyMap = {};
193184 return Column (
194185 mainAxisAlignment: MainAxisAlignment .start,
195186 crossAxisAlignment: CrossAxisAlignment .start,
@@ -245,15 +236,29 @@ class ProxiesTabViewState extends ConsumerState<ProxiesTabView>
245236 context.colorScheme.surface.opacity10,
246237 context.colorScheme.surface,
247238 ],
248- stops: const [0.0 , 0.1 ],
239+ stops: const [0.0 , 0.5 ],
249240 ),
250241 ),
251242 child: _buildMoreButton (),
252243 ),
253244 ),
254245 ),
255246 Expanded (
256- child: TabBarView (controller: _tabController, children: children),
247+ child: TabBarView (
248+ controller: _tabController,
249+ children: [
250+ for (final group in groups)
251+ ProxyGroupView (
252+ key: _keyMap.updateCacheValue (
253+ group.name,
254+ () => GlobalObjectKey <_ProxyGroupViewState >(group.name),
255+ ),
256+ group: group,
257+ columns: state.columns,
258+ cardType: state.proxyCardType,
259+ ),
260+ ],
261+ ),
257262 ),
258263 ],
259264 );
0 commit comments