This commit is contained in:
dmit.b
2026-07-05 12:42:04 +03:00
parent f011a121d7
commit 98cd704234
8 changed files with 81 additions and 69 deletions
+3
View File
@@ -8,6 +8,7 @@ class AuthService {
AuthService({http.Client? client}) : _client = client ?? http.Client();
Future<String> login(String login, String password) async {
print(ApiConfig.loginUrl);
final response = await _client.post(
Uri.parse(ApiConfig.loginUrl),
headers: {'Content-Type': 'application/json'},
@@ -17,6 +18,8 @@ class AuthService {
if (response.statusCode == 200) {
return response.body;
} else {
print(response.statusCode);
print(response.body);
throw Exception('Invalid credentials');
}
}
+9 -2
View File
@@ -1,7 +1,6 @@
import 'package:shared_preferences/shared_preferences.dart';
class SettingsService {
SettingsService(){initialize();}
static const String _baseUrlKey = 'server_base_url';
static const String _defaultBaseUrl =
'https://family-safety.onrender.com/api';
@@ -13,6 +12,7 @@ class SettingsService {
String get baseUrl => _baseUrl;
String? login;
String? pwd;
bool loggedIn=false;
Future<void> initialize() async {
if (_initialized) return;
@@ -34,7 +34,14 @@ class SettingsService {
pwd = pass;
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_loginKey, user);
await prefs.setString(_loginKey, user);
await prefs.setString(_pwdKey, pass);
}
Future<void> logOut() async {
final prefs = await SharedPreferences.getInstance();
login = null;
pwd = null;
await prefs.remove(_loginKey);
await prefs.remove(_pwdKey);
}
void resetToDefault() {