build for web server
This commit is contained in:
@@ -5,6 +5,8 @@ class Environment {
|
||||
static const String appwriteProjectName = 'Flutter Projects';
|
||||
static const String appwriteRealtimeCollectionId = '699e0b3d0006563a668b';
|
||||
static const String appwriteDatabaseId = '68a22ef90021b90f0f43';
|
||||
static const String appwriteApiKey =
|
||||
'standard_30ba2b755ae8ee1dc77a8ac6b44e1c72db276fd8adc1b96b0e66c8a8c5afe22bd5f9920db926f948f5bd6c08e1abcd6f5eb86f9ce81dfb49ee529c25ae1c7c407427647816b22a6ccc1dbaef8894a2d6301f10aa9315452a3b72b4d33634a424e40ede0935ad4d90c494fa05ca2eb1d066d13b76f305ef99439a28d735af97ff';
|
||||
static const String appwriteUserEMail = 'wei@a1.net';
|
||||
static const String appwritePasswd = '123456789';
|
||||
//static const String locationIQKey = 'pk.dea65023dc6fed25c96902bb97fb231d';
|
||||
|
||||
@@ -5,7 +5,6 @@ import '../services/appwrite_service.dart';
|
||||
import '../widgets/add_weight_dialog.dart';
|
||||
|
||||
class HomeController extends GetxController {
|
||||
final isLoggedIn = false.obs;
|
||||
final isloading = false.obs;
|
||||
final List<WeightModel> weights = <WeightModel>[].obs;
|
||||
final appwriteService = AppwriteService();
|
||||
@@ -27,23 +26,18 @@ class HomeController extends GetxController {
|
||||
if (weights.isNotEmpty) {
|
||||
weights.clear();
|
||||
}
|
||||
isLoggedIn.value = await appwriteService.login();
|
||||
if (isLoggedIn.value) {
|
||||
final documents = await appwriteService.getDocumentsFromCollection();
|
||||
if (documents.isEmpty) {
|
||||
print(
|
||||
'Keine Dokumente gefunden. Stelle sicher, dass die Collection Einträge enthält.',
|
||||
);
|
||||
} else {
|
||||
print(
|
||||
'Dokumente erfolgreich geladen: ${documents.length} Einträge gefunden.',
|
||||
);
|
||||
weights.assignAll(
|
||||
documents.map((doc) => WeightModel.fromJson(doc.data)),
|
||||
);
|
||||
}
|
||||
final loggedIn = await appwriteService.login();
|
||||
if (!loggedIn) {
|
||||
print('Login fehlgeschlagen – Daten können nicht geladen werden.');
|
||||
isloading.value = false;
|
||||
return;
|
||||
}
|
||||
final documents = await appwriteService.getDocumentsFromCollection();
|
||||
if (documents.isEmpty) {
|
||||
print('Keine Dokumente gefunden.');
|
||||
} else {
|
||||
print('Fehler beim Einloggen. Keine Daten geladen.');
|
||||
print('${documents.length} Einträge geladen.');
|
||||
weights.assignAll(documents.map((doc) => WeightModel.fromJson(doc.data)));
|
||||
}
|
||||
isloading.value = false;
|
||||
update();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:appwrite/models.dart';
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
@@ -7,23 +6,21 @@ import '../configs/environment.dart';
|
||||
class AppwriteService {
|
||||
static final String endpoint = Environment.appwritePublicEndpoint;
|
||||
static final String projectId = Environment.appwriteProjectId;
|
||||
static final String projectName = Environment.appwriteProjectName;
|
||||
static final String realtimeCollectionId =
|
||||
Environment.appwriteRealtimeCollectionId;
|
||||
static final String databaseId = Environment.appwriteDatabaseId;
|
||||
static final String userEMail = Environment.appwriteUserEMail;
|
||||
static final String userEmail = Environment.appwriteUserEMail;
|
||||
static final String passwd = Environment.appwritePasswd;
|
||||
|
||||
final Client _client = Client().setProject(projectId).setEndpoint(endpoint);
|
||||
|
||||
// ignore: unused_field
|
||||
late final Account _account;
|
||||
// ignore: unused_field
|
||||
late final Databases _databases;
|
||||
late final Account _account;
|
||||
bool _sessionActive = false;
|
||||
|
||||
AppwriteService._internal() {
|
||||
_account = Account(_client);
|
||||
_databases = Databases(_client);
|
||||
_account = Account(_client);
|
||||
}
|
||||
|
||||
static final AppwriteService _instance = AppwriteService._internal();
|
||||
@@ -31,45 +28,30 @@ class AppwriteService {
|
||||
/// Singleton instance getter
|
||||
factory AppwriteService() => _instance;
|
||||
|
||||
// login with e-Mail and password
|
||||
/// Login mit Email/Passwort. Erstellt nur eine neue Session wenn noch keine aktiv ist.
|
||||
Future<bool> login() async {
|
||||
await logout();
|
||||
if (_sessionActive) return true;
|
||||
try {
|
||||
final session = await _account.createEmailPasswordSession(
|
||||
email: userEMail,
|
||||
await _account.getSession(sessionId: 'current');
|
||||
_sessionActive = true;
|
||||
return true;
|
||||
} catch (_) {
|
||||
// Keine aktive Session – neu einloggen
|
||||
}
|
||||
try {
|
||||
await _account.createEmailPasswordSession(
|
||||
email: userEmail,
|
||||
password: passwd,
|
||||
);
|
||||
print('Login erfolgreich: ${session.$id}');
|
||||
_sessionActive = true;
|
||||
print('Appwrite Login erfolgreich');
|
||||
return true;
|
||||
} catch (e) {
|
||||
print('Login fehlgeschlagen: $e');
|
||||
print('Fehler beim Login: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// logout current user
|
||||
Future<bool> logout() async {
|
||||
try {
|
||||
await _account.deleteSession(sessionId: 'current');
|
||||
print('Logout erfolgreich');
|
||||
return true;
|
||||
} catch (e) {
|
||||
print('Logout fehlgeschlagen: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Get current user ID
|
||||
Future<String?> getCurrentUserId() async {
|
||||
try {
|
||||
final user = await _account.get();
|
||||
return user.$id;
|
||||
} catch (e) {
|
||||
print('Fehler beim Abrufen der Benutzer-ID: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Get List<Document> from Realtime Collection
|
||||
Future<List<Document>> getDocumentsFromCollection() async {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user