Removed Redundant Code
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
description: This file stores settings for Dart & Flutter DevTools.
|
||||
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||
extensions:
|
||||
@@ -1,11 +1,10 @@
|
||||
|
||||
|
||||
//const endPoint = 'http://10.15.45.11/v1';
|
||||
const endPoint = 'https://api.theonasanyas.com/v1';
|
||||
const projectId = 'chatapp';
|
||||
//const endPoint = 'https://api.theonasanyas.com/v1';
|
||||
const endPoint = 'https://cloud.appwrite.io/v1';
|
||||
const projectId = '678bdc7c00203eff8af5';
|
||||
const selfSigned = false;
|
||||
const databaseId = '676d7bc5000ffc9ca2a4';
|
||||
const userCollectionId = '676d7d05000253c91d27';
|
||||
const chatsCollectionId = '67734e8b002936f64abd';
|
||||
const convCollectionId = '67734e7f00205b8f40a6';
|
||||
const imageStorageBucket = '6771b9000011f84c14fa';
|
||||
const databaseId = '678c8659000a7d6b5bff';
|
||||
const userCollectionId = '678c865e002fe1cddd06';
|
||||
const chatsCollectionId = '678c866c0038822276ad';
|
||||
const convCollectionId = '678c8667001944dee794';
|
||||
const imageStorageBucket = '678d2162002a6770aaad';
|
||||
@@ -26,15 +26,9 @@ class MessagingProviders extends ChangeNotifier {
|
||||
// Auth Status
|
||||
AuthStatus? status;
|
||||
|
||||
//User Details
|
||||
models.User? user;
|
||||
models.Session? session;
|
||||
|
||||
// var _email;
|
||||
// var _name;
|
||||
// var _imageURL;
|
||||
// var _timeStamp;
|
||||
|
||||
static MessagingProviders instance = MessagingProviders();
|
||||
|
||||
MessagingProviders() {
|
||||
@@ -62,38 +56,51 @@ class MessagingProviders extends ChangeNotifier {
|
||||
|
||||
void loginWithEmailAndPassword(String _email, String _password) async {
|
||||
//
|
||||
status = AuthStatus.authenticating;
|
||||
notifyListeners();
|
||||
try {
|
||||
session = await account.createEmailPasswordSession(
|
||||
email: _email, password: _password);
|
||||
status != AuthStatus.error;
|
||||
|
||||
// user = await account.get();
|
||||
status = AuthStatus.authenticated;
|
||||
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;
|
||||
user = null;
|
||||
//
|
||||
try {
|
||||
status = AuthStatus.authenticating;
|
||||
session = await account.createEmailPasswordSession(
|
||||
email: _email, password: _password);
|
||||
|
||||
status = AuthStatus.authenticated;
|
||||
var value = await database.getDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: userCollectionId,
|
||||
documentId: session!.userId,
|
||||
);
|
||||
|
||||
SnackBarService.instance
|
||||
.showSnackBarSuccess("Welcome! ${value.data['name']}");
|
||||
NavigationService.instance.navigateToReplacement("home");
|
||||
account.deleteSession(sessionId: 'current');
|
||||
} on AppwriteException catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.message!);
|
||||
status = AuthStatus.error;
|
||||
user = null;
|
||||
//
|
||||
} on Exception catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.toString());
|
||||
//
|
||||
}
|
||||
notifyListeners();
|
||||
} on Exception catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.toString());
|
||||
//
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> createUser(String _email, String _password,
|
||||
Future<void> createUser(String _email, String _password, String _name,
|
||||
Future<void> onSuccess(String _uid)) async {
|
||||
notifyListeners();
|
||||
try {
|
||||
models.User _user = await account.create(
|
||||
userId: ID.unique(), email: _email, password: _password);
|
||||
user = await account.create(
|
||||
userId: ID.unique(), email: _email, password: _password, name: _name);
|
||||
|
||||
status = AuthStatus.authenticated;
|
||||
await onSuccess(_user.$id);
|
||||
SnackBarService.instance.showSnackBarSuccess("Welcome! ${_user.email}");
|
||||
await onSuccess(user!.$id);
|
||||
SnackBarService.instance.showSnackBarSuccess("Welcome! ${user!.name}");
|
||||
NavigationService.instance.goBack();
|
||||
NavigationService.instance.navigateToReplacement("home");
|
||||
} on AppwriteException catch (e) {
|
||||
@@ -109,47 +116,60 @@ class MessagingProviders extends ChangeNotifier {
|
||||
|
||||
Future<void> createUserInDB(
|
||||
String _documentId, String _email, String _name, String _imageURL) async {
|
||||
notifyListeners();
|
||||
try {
|
||||
await database.createDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: userCollectionId,
|
||||
documentId: _documentId,
|
||||
data: {
|
||||
"name": _name,
|
||||
"email": _email,
|
||||
"timeStamp": DateTime.now().toUtc().toIso8601String(),
|
||||
"image": _imageURL
|
||||
});
|
||||
databaseId: databaseId,
|
||||
collectionId: userCollectionId,
|
||||
documentId: _documentId,
|
||||
data: {
|
||||
"name": _name,
|
||||
"email": _email,
|
||||
"lastSeen": DateTime.now().toUtc().toIso8601String(),
|
||||
"image": _imageURL
|
||||
},
|
||||
permissions: [
|
||||
Permission.read(Role.any()),
|
||||
//Permission.update(Role.user(_documentId)),
|
||||
],
|
||||
);
|
||||
|
||||
status = AuthStatus.authenticated;
|
||||
} on AppwriteException catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.message!);
|
||||
status = AuthStatus.error;
|
||||
user = null;
|
||||
//
|
||||
} on Exception catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.toString());
|
||||
status = AuthStatus.error;
|
||||
user = null;
|
||||
//
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
uploadUserImage(XFile? file, String _uid) async {
|
||||
notifyListeners();
|
||||
try {
|
||||
File _file = File(file!.path);
|
||||
var _test = await storage.createFile(
|
||||
var _message = await storage.createFile(
|
||||
bucketId: imageStorageBucket,
|
||||
fileId: ID.unique(),
|
||||
file: InputFile.fromPath(path: _file.path, filename: file.name),
|
||||
permissions: [
|
||||
Permission.read(Role.any()),
|
||||
// Permission.update(Role.user(_uid))
|
||||
],
|
||||
);
|
||||
|
||||
return "$endPoint/storage/buckets/${_test.bucketId}/files/${_test.$id}/view?project=$projectId";
|
||||
return "$endPoint/storage/buckets/${_message.bucketId}/files/${_message.$id}/view?project=$projectId";
|
||||
} on AppwriteException catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.message!);
|
||||
print(e.message);
|
||||
//
|
||||
} on Exception catch (e) {
|
||||
status = AuthStatus.error;
|
||||
user = null;
|
||||
SnackBarService.instance.showSnackBarError(e.toString());
|
||||
//
|
||||
}
|
||||
|
||||
+3
-4
@@ -5,7 +5,9 @@ import 'package:messaging_app/service/navigation_service.dart';
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
runApp(const MessagingApp());
|
||||
runApp(
|
||||
MessagingApp(),
|
||||
);
|
||||
}
|
||||
|
||||
class MessagingApp extends StatelessWidget {
|
||||
@@ -14,7 +16,6 @@ class MessagingApp extends StatelessWidget {
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return MaterialApp(
|
||||
title: 'Messaging App',
|
||||
navigatorKey: NavigationService.instance.navigatorKey,
|
||||
@@ -30,6 +31,4 @@ class MessagingApp extends StatelessWidget {
|
||||
// home: RegisterationPage(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -123,7 +123,6 @@ class _RegisterationPageState extends State<RegisterationPage> {
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
XFile? _imageFile = await MediaService.instance.getImageFromLibrary();
|
||||
_imageFile!.name;
|
||||
setState(() {
|
||||
_image = _imageFile;
|
||||
});
|
||||
@@ -225,18 +224,26 @@ class _RegisterationPageState extends State<RegisterationPage> {
|
||||
width: _deviceWidth,
|
||||
child: MaterialButton(
|
||||
onPressed: () {
|
||||
String name = _name!;
|
||||
if (_image == null) {
|
||||
SnackBarService.instance
|
||||
.showSnackBarError("Please Select Image");
|
||||
}
|
||||
if (_formKey.currentState!.validate() && _image != null) {
|
||||
//
|
||||
_auth.createUser(_email!, _password!, (String _uid) async {
|
||||
var _url = await _auth.uploadUserImage(_image, _uid);
|
||||
_auth.createUserInDB(_uid, _email!, _name!, _url);
|
||||
if (_auth.status == AuthStatus.authenticated) {
|
||||
_auth.loginWithEmailAndPassword(_email!, _password!);
|
||||
}
|
||||
//
|
||||
});
|
||||
//Login User
|
||||
// _auth.loginWithEmailAndPassword(_email!, _password!);
|
||||
_auth.createUser(
|
||||
_email!,
|
||||
_password!,
|
||||
name,
|
||||
(String _uid) async {
|
||||
var _url = await _auth.uploadUserImage(_image, _uid);
|
||||
_auth.createUserInDB(_uid, _email!, name, _url);
|
||||
if (_auth.status == AuthStatus.authenticated) {
|
||||
_auth.loginWithEmailAndPassword(_email!, _password!);
|
||||
}
|
||||
//
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
color: Colors.blue,
|
||||
|
||||
+2
-13
@@ -34,7 +34,7 @@ dependencies:
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.8
|
||||
appwrite: 13.0.0
|
||||
appwrite: 13.1.1
|
||||
timeago: ^3.7.0
|
||||
flutter_spinkit: ^5.2.1
|
||||
provider: ^6.1.2
|
||||
@@ -44,22 +44,11 @@ dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
# The "flutter_lints" package below contains a set of recommended lints to
|
||||
# encourage good coding practices. The lint set provided by the package is
|
||||
# activated in the `analysis_options.yaml` file located at the root of your
|
||||
# package. See that file for information about deactivating specific lint
|
||||
# rules and activating additional ones.
|
||||
|
||||
flutter_lints: ^5.0.0
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
# The following section is specific to Flutter packages.
|
||||
flutter:
|
||||
|
||||
# The following line ensures that the Material Icons font is
|
||||
# included with your application, so that you can use the icons in
|
||||
# the material Icons class.
|
||||
uses-material-design: true
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
|
||||
Reference in New Issue
Block a user