Pages Implementation
Implemented Profile and Recent Conversation skeleton pages
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
import 'package:appwrite/models.dart' as models;
|
||||
import 'package:appwrite/models.dart' as model;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:messaging_app/components/constants.dart';
|
||||
import 'package:messaging_app/models/conversations.dart';
|
||||
import 'package:messaging_app/models/users.dart';
|
||||
import 'package:messaging_app/service/navigation_service.dart';
|
||||
import 'package:messaging_app/service/snackbar_service.dart';
|
||||
|
||||
@@ -24,29 +25,31 @@ class MessagingProviders extends ChangeNotifier {
|
||||
late final Storage storage;
|
||||
|
||||
// Auth Status
|
||||
AuthStatus? status;
|
||||
|
||||
models.User? user;
|
||||
models.Session? session;
|
||||
late AuthStatus status;
|
||||
late model.User? user;
|
||||
late model.Session session;
|
||||
|
||||
static MessagingProviders instance = MessagingProviders();
|
||||
|
||||
MessagingProviders() {
|
||||
init();
|
||||
loadUser();
|
||||
_init();
|
||||
_loadUser();
|
||||
}
|
||||
|
||||
init() {
|
||||
_init() {
|
||||
client.setEndpoint(endPoint).setProject(projectId).setSelfSigned();
|
||||
account = Account(client);
|
||||
database = Databases(client);
|
||||
storage = Storage(client);
|
||||
}
|
||||
|
||||
loadUser() async {
|
||||
_loadUser() async {
|
||||
try {
|
||||
user = await account.get();
|
||||
status = AuthStatus.authenticated;
|
||||
if (user != null) {
|
||||
status = AuthStatus.authenticated;
|
||||
_autoLogin();
|
||||
}
|
||||
} catch (e) {
|
||||
status = AuthStatus.notAuthenticated;
|
||||
} finally {
|
||||
@@ -54,7 +57,11 @@ class MessagingProviders extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void loginWithEmailAndPassword(String _email, String _password) async {
|
||||
void _autoLogin() {
|
||||
NavigationService.instance.navigateToReplacement("home");
|
||||
}
|
||||
|
||||
void login(String _email, String _password) async {
|
||||
//
|
||||
notifyListeners();
|
||||
try {
|
||||
@@ -65,17 +72,11 @@ class MessagingProviders extends ChangeNotifier {
|
||||
session = await account.createEmailPasswordSession(
|
||||
email: _email, password: _password);
|
||||
|
||||
user = await account.get();
|
||||
status = AuthStatus.authenticated;
|
||||
var value = await database.getDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: userCollectionId,
|
||||
documentId: session!.userId,
|
||||
);
|
||||
|
||||
SnackBarService.instance
|
||||
.showSnackBarSuccess("Welcome! ${value.data['name']}");
|
||||
SnackBarService.instance.showSnackBarSuccess("Welcome! ${user!.name}");
|
||||
NavigationService.instance.navigateToReplacement("home");
|
||||
account.deleteSession(sessionId: 'current');
|
||||
} on AppwriteException catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.message!);
|
||||
status = AuthStatus.error;
|
||||
@@ -91,6 +92,22 @@ class MessagingProviders extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void logout() async {
|
||||
try {
|
||||
await account.deleteSession(sessionId: 'current');
|
||||
user = null;
|
||||
status = AuthStatus.notAuthenticated;
|
||||
// await onSuccess();
|
||||
await NavigationService.instance.navigateToReplacement("login");
|
||||
SnackBarService.instance.showSnackBarError("Logged out Successfully");
|
||||
} on AppwriteException catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.message!);
|
||||
} on Exception catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.toString());
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> createUser(String _email, String _password, String _name,
|
||||
Future<void> onSuccess(String _uid)) async {
|
||||
notifyListeners();
|
||||
@@ -149,6 +166,43 @@ class MessagingProviders extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Stream<Users> getUser(String userId) {
|
||||
var _userData = database.getDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: userCollectionId,
|
||||
documentId: userId,
|
||||
);
|
||||
|
||||
return _userData.asStream().map((_snapshot) {
|
||||
return Users.fromData(_snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
Stream<List<Conversations>> getUserConversation(String userId) {
|
||||
//
|
||||
List<dynamic> _chatId = [];
|
||||
List<dynamic> _details = [];
|
||||
List<Conversations> _returnValue = [];
|
||||
|
||||
var _conversationData = database.getDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: convCollectionId,
|
||||
documentId: userId.trim(),
|
||||
);
|
||||
|
||||
return _conversationData.asStream().map(
|
||||
(_snapshot) {
|
||||
_chatId = _snapshot.data['chatId'];
|
||||
_details = _snapshot.data['details'];
|
||||
|
||||
for (int i = 0; i < _chatId.length; i++) {
|
||||
_returnValue.add(Conversations.fromData(_chatId[i], _details[i]));
|
||||
}
|
||||
return _returnValue;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
uploadUserImage(XFile? file, String _uid) async {
|
||||
notifyListeners();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user