You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.0 KiB
32 lines
1.0 KiB
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
import '../pages/sign_in_page.dart'; |
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
Future<String> getBaseUrl() async { |
|
try { |
|
String savedValue = await getSavedValue(); |
|
|
|
// Check if savedValue is a domain, IP with or without port |
|
String baseUrl; |
|
|
|
if (savedValue.contains(':')) { |
|
// If savedValue contains a colon, assume it's an IP with port |
|
baseUrl = 'http://$savedValue/api/v1'; |
|
} else if (RegExp(r'^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$').hasMatch(savedValue)) { |
|
// If savedValue matches the domain pattern, assume it's a domain |
|
baseUrl = 'https://$savedValue/api/v1'; |
|
} else { |
|
// If it doesn't match both patterns, assume it's an IP without port |
|
baseUrl = 'https://$savedValue/api/v1'; |
|
} |
|
|
|
return baseUrl; |
|
} catch (e) { |
|
// Error handling |
|
print('Error reading SharedPreferences: $e'); |
|
return ''; // Or any other default value in case of an error |
|
} |
|
}
|
|
|