Files
2026-07-14 17:37:17 +03:00

32 lines
1.1 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:shared_preferences/shared_preferences.dart';
/// Sunucu URL'si ve API key gibi ayarları kalıcı olarak saklar.
class SettingsService {
static const _keyServerUrl = 'server_url';
static const _keyApiKey = 'api_key';
Future<String?> getServerUrl() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString(_keyServerUrl);
}
Future<String?> getApiKey() async {
final prefs = await SharedPreferences.getInstance();
final key = prefs.getString(_keyApiKey);
return (key == null || key.isEmpty) ? null : key;
}
Future<void> save({required String serverUrl, required String apiKey}) async {
final prefs = await SharedPreferences.getInstance();
// Sonundaki "/" karakterini temizle, karışıklık olmasın.
final cleanUrl = serverUrl.trim().replaceAll(RegExp(r'/+$'), '');
await prefs.setString(_keyServerUrl, cleanUrl);
await prefs.setString(_keyApiKey, apiKey.trim());
}
Future<bool> hasSettings() async {
final url = await getServerUrl();
return url != null && url.isNotEmpty;
}
}