@@ -118,7 +118,9 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
118118 }
119119
120120 Future <void > _loadAllPings () async {
121- final groupedConfigs = _groupConfigsByHost (widget.configs);
121+ final provider = Provider .of <V2RayProvider >(context, listen: false );
122+ final configs = provider.configs;
123+ final groupedConfigs = _groupConfigsByHost (configs);
122124 for (var host in groupedConfigs.keys) {
123125 if (! mounted) return ;
124126 final configsForHost = groupedConfigs[host]! ;
@@ -344,8 +346,9 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
344346
345347 @override
346348 Widget build (BuildContext context) {
347- final provider = Provider .of <V2RayProvider >(context, listen: false );
349+ final provider = Provider .of <V2RayProvider >(context, listen: true );
348350 final subscriptions = provider.subscriptions;
351+ final configs = provider.configs;
349352
350353 final filterOptions = ['All' , 'Local' , ...subscriptions.map ((sub) => sub.name)];
351354
@@ -385,7 +388,9 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
385388 final allSubscriptionConfigIds = subscriptions
386389 .expand ((sub) => sub.configIds)
387390 .toSet ();
388- final localConfigs = widget.configs
391+ final provider = Provider .of <V2RayProvider >(context, listen: false );
392+ final allConfigs = provider.configs;
393+ final localConfigs = allConfigs
389394 .where ((config) => ! allSubscriptionConfigIds.contains (config.id))
390395 .toList ();
391396
@@ -406,8 +411,10 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
406411 configIds: [],
407412 ),
408413 );
414+ final provider = Provider .of <V2RayProvider >(context, listen: false );
415+ final allConfigs = provider.configs;
409416 final configsToTest =
410- widget.configs
417+ allConfigs
411418 .where (
412419 (config) =>
413420 subscription.configIds.contains (config.id),
@@ -449,13 +456,13 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
449456
450457 List <V2RayConfig > filteredConfigs = [];
451458 if (_selectedFilter == 'All' ) {
452- filteredConfigs = List .from (widget. configs);
459+ filteredConfigs = List .from (configs);
453460 } else if (_selectedFilter == 'Local' ) {
454461 // Filter configs that don't belong to any subscription
455462 final allSubscriptionConfigIds = subscriptions
456463 .expand ((sub) => sub.configIds)
457464 .toSet ();
458- filteredConfigs = widget. configs
465+ filteredConfigs = configs
459466 .where ((config) => ! allSubscriptionConfigIds.contains (config.id))
460467 .toList ();
461468 } else {
@@ -471,7 +478,7 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
471478 ),
472479 );
473480 filteredConfigs =
474- widget. configs
481+ configs
475482 .where ((config) => subscription.configIds.contains (config.id))
476483 .toList ();
477484 }
@@ -482,13 +489,17 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
482489 final pingA = _pings[a.id];
483490 final pingB = _pings[b.id];
484491
485- // Handle null pings - put them at the bottom
486- if (pingA == null && pingB == null ) return 0 ;
487- if (pingA == null ) return 1 ;
488- if (pingB == null ) return - 1 ;
492+ // Check if ping values are valid (not null, -1, or 0)
493+ final isValidPingA = pingA != null && pingA > 0 ;
494+ final isValidPingB = pingB != null && pingB > 0 ;
495+
496+ // Handle invalid pings - put them at the bottom
497+ if (! isValidPingA && ! isValidPingB) return 0 ;
498+ if (! isValidPingA) return 1 ;
499+ if (! isValidPingB) return - 1 ;
489500
490- // Sort by ping value
491- return _sortAscending ? pingA.compareTo (pingB) : pingB.compareTo (pingA);
501+ // Sort by ping value (only valid pings reach here)
502+ return _sortAscending ? pingA! .compareTo (pingB! ) : pingB! .compareTo (pingA! );
492503 });
493504 }
494505
@@ -783,7 +794,7 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
783794
784795 final config = filteredConfigs[index - 1 ];
785796 final isSelected =
786- widget .selectedConfig? .id == config.id;
797+ provider .selectedConfig? .id == config.id;
787798
788799 return Card (
789800 margin: const EdgeInsets .only (bottom: 12 ),
0 commit comments