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.
25 lines
895 B
25 lines
895 B
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
Future<String> getBaseUrl() async { |
|
try { |
|
SharedPreferences prefs = await SharedPreferences.getInstance(); |
|
String ipAddress = |
|
prefs.getString('ipAddress') ?? '192.168.1.14'; // Default value |
|
String port = prefs.getString('port') ?? '8000'; // Default value |
|
|
|
String baseUrl = 'http://$ipAddress:$port/api/v1'; |
|
|
|
return baseUrl; |
|
} catch (e) { |
|
// Penanganan kesalahan |
|
print('Error reading SharedPreferences: $e'); |
|
return ''; // Atau nilai default lainnya jika terjadi kesalahan |
|
} |
|
} |
|
|
|
// return 'http://$ipAddress:$port/api/v1'; |
|
// String baseUrl = 'http://192.168.0.18:8000/api/v1'; |
|
// Gunakan fungsi ini saat diperlukan, misalnya di tempat-tempat yang membutuhkan baseUrl |
|
// Contoh penggunaan: String url = await getBaseUrl();
|
|
|