Skip to content

Commit def23ab

Browse files
author
code3-dev
committed
fix sort
1 parent 9de430c commit def23ab

File tree

6 files changed

+31
-20
lines changed

6 files changed

+31
-20
lines changed

android/app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ android {
2626
// For more information, see: https://flutter.dev/to/review-gradle-config.
2727
minSdk = flutter.minSdkVersion
2828
targetSdk = flutter.targetSdkVersion
29-
versionCode = 13
30-
versionName = "2.1.5"
29+
versionCode = 14
30+
versionName = "2.2.0"
3131
}
3232

3333
buildTypes {

lib/models/app_update.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class AppUpdate {
66
final String messText;
77

88
// Current app version - manually set
9-
static const String currentAppVersion = '2.1.5';
9+
static const String currentAppVersion = '2.2.0';
1010

1111
AppUpdate({required this.version, required this.url, required this.messText});
1212

lib/screens/about_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AboutScreen extends StatelessWidget {
4848

4949
// App Version
5050
const Text(
51-
'Version 2.1.5',
51+
'Version 2.2.0',
5252
style: TextStyle(fontSize: 16, color: Colors.grey),
5353
),
5454

lib/screens/server_selection_screen.dart

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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),

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,5 +766,5 @@ packages:
766766
source: hosted
767767
version: "6.5.0"
768768
sdks:
769-
dart: ">=3.7.2 <4.0.0"
769+
dart: ">=3.8.1 <4.0.0"
770770
flutter: ">=3.27.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1919
version: 1.2.0+1
2020

2121
environment:
22-
sdk: ^3.7.2
22+
sdk: ^3.8.1
2323

2424
# Dependencies specify other packages that your package needs in order to work.
2525
# To automatically upgrade your package dependencies to the latest versions

0 commit comments

Comments
 (0)