a bunch of flutter updates
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class AppConstants {
|
||||
static const String _serverUrlKey = 'server_base_url';
|
||||
static const String _selectedYoloModelKey = 'selected_yolo_model';
|
||||
|
||||
// Ambil base URL dari SharedPreferences
|
||||
static Future<String?> getServerUrl() async {
|
||||
@@ -12,18 +13,29 @@ class AppConstants {
|
||||
// Simpan URL setelah berhasil connect
|
||||
static Future<void> setServerUrl(String url) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
// Trim trailing slash
|
||||
final cleaned = url.endsWith('/') ? url.substring(0, url.length - 1) : url;
|
||||
final cleaned = normalizeServerUrl(url);
|
||||
await prefs.setString(_serverUrlKey, cleaned);
|
||||
}
|
||||
|
||||
static String normalizeServerUrl(String url) {
|
||||
var cleaned = url.trim();
|
||||
if (!cleaned.startsWith('http://') && !cleaned.startsWith('https://')) {
|
||||
cleaned = 'http://$cleaned';
|
||||
}
|
||||
while (cleaned.endsWith('/')) {
|
||||
cleaned = cleaned.substring(0, cleaned.length - 1);
|
||||
}
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
static Future<void> clearServerUrl() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(_serverUrlKey);
|
||||
}
|
||||
|
||||
static String buildApiUrl(String baseUrl) => '$baseUrl/api/v1';
|
||||
static String buildWsUrl(String baseUrl) => baseUrl.replaceFirst('http', 'ws') + '/ws';
|
||||
static String buildWsUrl(String baseUrl) =>
|
||||
'${baseUrl.replaceFirst('http', 'ws')}/ws';
|
||||
|
||||
// Timeouts
|
||||
static const Duration connectTimeout = Duration(seconds: 10);
|
||||
@@ -39,6 +51,16 @@ class AppConstants {
|
||||
static const String yoloLabelsPath = 'assets/models/labels.txt';
|
||||
static const int yoloInputSize = 640;
|
||||
|
||||
static Future<String> getSelectedYoloModelPath() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString(_selectedYoloModelKey) ?? yoloModelPath;
|
||||
}
|
||||
|
||||
static Future<void> setSelectedYoloModelPath(String path) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_selectedYoloModelKey, path);
|
||||
}
|
||||
|
||||
// Agora - ganti dengan App ID dari agora.io
|
||||
static const String agoraAppId = 'YOUR_AGORA_APP_ID';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user