Siopas Inventory PETI for ISTW Mobile
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.
 
 
 
 
 
 

36 lines
1.3 KiB

import '../pages/login/controller/loginController.dart'; // Sesuaikan path dengan struktur proyek Anda
Future<String> getBaseUrl() async {
try {
List ipDomainList = await ControllerLogin().fetchData();
if (ipDomainList.isNotEmpty) {
String savedValue = ipDomainList.first['ipOrDomain'] ?? '';
// 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;
} else {
// Handle jika tidak ada data di database (misalnya, berikan nilai default atau tampilkan pesan kesalahan)
print('No data found in database.');
return ''; // Atau berikan nilai default lainnya sesuai kebutuhan
}
} catch (e) {
// Handle kesalahan pembacaan dari database
print('Error reading data from database: $e');
return ''; // Atau berikan nilai default lainnya sesuai kebutuhan
}
}