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 = 'http://10.15.45.11/v1';
|
||||||
const endPoint = 'https://api.theonasanyas.com/v1';
|
//const endPoint = 'https://api.theonasanyas.com/v1';
|
||||||
const projectId = 'chatapp';
|
const endPoint = 'https://cloud.appwrite.io/v1';
|
||||||
|
const projectId = '678bdc7c00203eff8af5';
|
||||||
const selfSigned = false;
|
const selfSigned = false;
|
||||||
const databaseId = '676d7bc5000ffc9ca2a4';
|
const databaseId = '678c8659000a7d6b5bff';
|
||||||
const userCollectionId = '676d7d05000253c91d27';
|
const userCollectionId = '678c865e002fe1cddd06';
|
||||||
const chatsCollectionId = '67734e8b002936f64abd';
|
const chatsCollectionId = '678c866c0038822276ad';
|
||||||
const convCollectionId = '67734e7f00205b8f40a6';
|
const convCollectionId = '678c8667001944dee794';
|
||||||
const imageStorageBucket = '6771b9000011f84c14fa';
|
const imageStorageBucket = '678d2162002a6770aaad';
|
||||||
@@ -26,15 +26,9 @@ class MessagingProviders extends ChangeNotifier {
|
|||||||
// Auth Status
|
// Auth Status
|
||||||
AuthStatus? status;
|
AuthStatus? status;
|
||||||
|
|
||||||
//User Details
|
|
||||||
models.User? user;
|
models.User? user;
|
||||||
models.Session? session;
|
models.Session? session;
|
||||||
|
|
||||||
// var _email;
|
|
||||||
// var _name;
|
|
||||||
// var _imageURL;
|
|
||||||
// var _timeStamp;
|
|
||||||
|
|
||||||
static MessagingProviders instance = MessagingProviders();
|
static MessagingProviders instance = MessagingProviders();
|
||||||
|
|
||||||
MessagingProviders() {
|
MessagingProviders() {
|
||||||
@@ -62,17 +56,26 @@ class MessagingProviders extends ChangeNotifier {
|
|||||||
|
|
||||||
void loginWithEmailAndPassword(String _email, String _password) async {
|
void loginWithEmailAndPassword(String _email, String _password) async {
|
||||||
//
|
//
|
||||||
status = AuthStatus.authenticating;
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
|
status != AuthStatus.error;
|
||||||
|
|
||||||
|
try {
|
||||||
|
status = AuthStatus.authenticating;
|
||||||
session = await account.createEmailPasswordSession(
|
session = await account.createEmailPasswordSession(
|
||||||
email: _email, password: _password);
|
email: _email, password: _password);
|
||||||
|
|
||||||
// user = await account.get();
|
|
||||||
status = AuthStatus.authenticated;
|
status = AuthStatus.authenticated;
|
||||||
SnackBarService.instance.showSnackBarSuccess("Welcome! ${user!.name}");
|
var value = await database.getDocument(
|
||||||
|
databaseId: databaseId,
|
||||||
|
collectionId: userCollectionId,
|
||||||
|
documentId: session!.userId,
|
||||||
|
);
|
||||||
|
|
||||||
|
SnackBarService.instance
|
||||||
|
.showSnackBarSuccess("Welcome! ${value.data['name']}");
|
||||||
NavigationService.instance.navigateToReplacement("home");
|
NavigationService.instance.navigateToReplacement("home");
|
||||||
// account.deleteSession(sessionId: 'current');
|
account.deleteSession(sessionId: 'current');
|
||||||
} on AppwriteException catch (e) {
|
} on AppwriteException catch (e) {
|
||||||
SnackBarService.instance.showSnackBarError(e.message!);
|
SnackBarService.instance.showSnackBarError(e.message!);
|
||||||
status = AuthStatus.error;
|
status = AuthStatus.error;
|
||||||
@@ -83,17 +86,21 @@ class MessagingProviders extends ChangeNotifier {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
} on Exception catch (e) {
|
||||||
|
SnackBarService.instance.showSnackBarError(e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createUser(String _email, String _password,
|
Future<void> createUser(String _email, String _password, String _name,
|
||||||
Future<void> onSuccess(String _uid)) async {
|
Future<void> onSuccess(String _uid)) async {
|
||||||
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
models.User _user = await account.create(
|
user = await account.create(
|
||||||
userId: ID.unique(), email: _email, password: _password);
|
userId: ID.unique(), email: _email, password: _password, name: _name);
|
||||||
|
|
||||||
status = AuthStatus.authenticated;
|
status = AuthStatus.authenticated;
|
||||||
await onSuccess(_user.$id);
|
await onSuccess(user!.$id);
|
||||||
SnackBarService.instance.showSnackBarSuccess("Welcome! ${_user.email}");
|
SnackBarService.instance.showSnackBarSuccess("Welcome! ${user!.name}");
|
||||||
NavigationService.instance.goBack();
|
NavigationService.instance.goBack();
|
||||||
NavigationService.instance.navigateToReplacement("home");
|
NavigationService.instance.navigateToReplacement("home");
|
||||||
} on AppwriteException catch (e) {
|
} on AppwriteException catch (e) {
|
||||||
@@ -109,6 +116,7 @@ class MessagingProviders extends ChangeNotifier {
|
|||||||
|
|
||||||
Future<void> createUserInDB(
|
Future<void> createUserInDB(
|
||||||
String _documentId, String _email, String _name, String _imageURL) async {
|
String _documentId, String _email, String _name, String _imageURL) async {
|
||||||
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
await database.createDocument(
|
await database.createDocument(
|
||||||
databaseId: databaseId,
|
databaseId: databaseId,
|
||||||
@@ -117,39 +125,51 @@ class MessagingProviders extends ChangeNotifier {
|
|||||||
data: {
|
data: {
|
||||||
"name": _name,
|
"name": _name,
|
||||||
"email": _email,
|
"email": _email,
|
||||||
"timeStamp": DateTime.now().toUtc().toIso8601String(),
|
"lastSeen": DateTime.now().toUtc().toIso8601String(),
|
||||||
"image": _imageURL
|
"image": _imageURL
|
||||||
});
|
},
|
||||||
|
permissions: [
|
||||||
|
Permission.read(Role.any()),
|
||||||
|
//Permission.update(Role.user(_documentId)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
status = AuthStatus.authenticated;
|
status = AuthStatus.authenticated;
|
||||||
} on AppwriteException catch (e) {
|
} on AppwriteException catch (e) {
|
||||||
SnackBarService.instance.showSnackBarError(e.message!);
|
SnackBarService.instance.showSnackBarError(e.message!);
|
||||||
|
status = AuthStatus.error;
|
||||||
|
user = null;
|
||||||
//
|
//
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
SnackBarService.instance.showSnackBarError(e.toString());
|
SnackBarService.instance.showSnackBarError(e.toString());
|
||||||
|
status = AuthStatus.error;
|
||||||
|
user = null;
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadUserImage(XFile? file, String _uid) async {
|
uploadUserImage(XFile? file, String _uid) async {
|
||||||
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
File _file = File(file!.path);
|
File _file = File(file!.path);
|
||||||
var _test = await storage.createFile(
|
var _message = await storage.createFile(
|
||||||
bucketId: imageStorageBucket,
|
bucketId: imageStorageBucket,
|
||||||
fileId: ID.unique(),
|
fileId: ID.unique(),
|
||||||
file: InputFile.fromPath(path: _file.path, filename: file.name),
|
file: InputFile.fromPath(path: _file.path, filename: file.name),
|
||||||
permissions: [
|
permissions: [
|
||||||
Permission.read(Role.any()),
|
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) {
|
} on AppwriteException catch (e) {
|
||||||
SnackBarService.instance.showSnackBarError(e.message!);
|
SnackBarService.instance.showSnackBarError(e.message!);
|
||||||
print(e.message);
|
|
||||||
//
|
//
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
|
status = AuthStatus.error;
|
||||||
|
user = null;
|
||||||
SnackBarService.instance.showSnackBarError(e.toString());
|
SnackBarService.instance.showSnackBarError(e.toString());
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -5,7 +5,9 @@ import 'package:messaging_app/service/navigation_service.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
runApp(const MessagingApp());
|
runApp(
|
||||||
|
MessagingApp(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessagingApp extends StatelessWidget {
|
class MessagingApp extends StatelessWidget {
|
||||||
@@ -14,7 +16,6 @@ class MessagingApp extends StatelessWidget {
|
|||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Messaging App',
|
title: 'Messaging App',
|
||||||
navigatorKey: NavigationService.instance.navigatorKey,
|
navigatorKey: NavigationService.instance.navigatorKey,
|
||||||
@@ -30,6 +31,4 @@ class MessagingApp extends StatelessWidget {
|
|||||||
// home: RegisterationPage(),
|
// home: RegisterationPage(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ class _RegisterationPageState extends State<RegisterationPage> {
|
|||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
XFile? _imageFile = await MediaService.instance.getImageFromLibrary();
|
XFile? _imageFile = await MediaService.instance.getImageFromLibrary();
|
||||||
_imageFile!.name;
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_image = _imageFile;
|
_image = _imageFile;
|
||||||
});
|
});
|
||||||
@@ -225,18 +224,26 @@ class _RegisterationPageState extends State<RegisterationPage> {
|
|||||||
width: _deviceWidth,
|
width: _deviceWidth,
|
||||||
child: MaterialButton(
|
child: MaterialButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
String name = _name!;
|
||||||
|
if (_image == null) {
|
||||||
|
SnackBarService.instance
|
||||||
|
.showSnackBarError("Please Select Image");
|
||||||
|
}
|
||||||
if (_formKey.currentState!.validate() && _image != null) {
|
if (_formKey.currentState!.validate() && _image != null) {
|
||||||
//
|
//
|
||||||
_auth.createUser(_email!, _password!, (String _uid) async {
|
_auth.createUser(
|
||||||
|
_email!,
|
||||||
|
_password!,
|
||||||
|
name,
|
||||||
|
(String _uid) async {
|
||||||
var _url = await _auth.uploadUserImage(_image, _uid);
|
var _url = await _auth.uploadUserImage(_image, _uid);
|
||||||
_auth.createUserInDB(_uid, _email!, _name!, _url);
|
_auth.createUserInDB(_uid, _email!, name, _url);
|
||||||
if (_auth.status == AuthStatus.authenticated) {
|
if (_auth.status == AuthStatus.authenticated) {
|
||||||
_auth.loginWithEmailAndPassword(_email!, _password!);
|
_auth.loginWithEmailAndPassword(_email!, _password!);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
});
|
},
|
||||||
//Login User
|
);
|
||||||
// _auth.loginWithEmailAndPassword(_email!, _password!);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
|
|||||||
+2
-13
@@ -34,7 +34,7 @@ dependencies:
|
|||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.8
|
cupertino_icons: ^1.0.8
|
||||||
appwrite: 13.0.0
|
appwrite: 13.1.1
|
||||||
timeago: ^3.7.0
|
timeago: ^3.7.0
|
||||||
flutter_spinkit: ^5.2.1
|
flutter_spinkit: ^5.2.1
|
||||||
provider: ^6.1.2
|
provider: ^6.1.2
|
||||||
@@ -44,22 +44,11 @@ dev_dependencies:
|
|||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
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
|
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:
|
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
|
uses-material-design: true
|
||||||
|
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
|
|||||||
Reference in New Issue
Block a user