diff --git a/lib/pages/chat_page.dart b/lib/pages/chat_page.dart index ea8bc2a..3f70d29 100644 --- a/lib/pages/chat_page.dart +++ b/lib/pages/chat_page.dart @@ -95,8 +95,9 @@ class _ChatPageState extends State { Widget chatHeader = Text(widget.chatTitle); Widget? userPic; if (widget.profileImageUrl != null && widget.profileImageUrl!.isNotEmpty) { - userPic = - CircleAvatar(backgroundImage: NetworkImage(widget.profileImageUrl!)); + userPic = CircleAvatar( + backgroundImage: NetworkImage(widget.profileImageUrl!), + ); } if (userPic != null) { chatHeader = Row( diff --git a/lib/pages/edit_profile_page.dart b/lib/pages/edit_profile_page.dart index 68d1365..8f54b07 100644 --- a/lib/pages/edit_profile_page.dart +++ b/lib/pages/edit_profile_page.dart @@ -45,8 +45,6 @@ class EditProfilePageState extends State { if (pickedFile != null) { CroppedFile? croppedFile = await ImageCropper().cropImage( sourcePath: pickedFile.path, - //compressFormat: ImageCompressFormat.jpg, - //compressQuality: 100, aspectRatioPresets: [ CropAspectRatioPreset.square, CropAspectRatioPreset.ratio3x2, @@ -75,7 +73,10 @@ class EditProfilePageState extends State { height: 400, ), viewPort: const CroppieViewPort( - width: 360, height: 360, type: 'circle'), + width: 360, + height: 360, + type: 'circle', + ), enableExif: true, enableZoom: true, showZoomer: true, diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 2f00c03..1cd43b1 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -14,7 +14,6 @@ class HomePage extends StatelessWidget { backgroundColor: Colors.transparent, ), drawer: const MyDrawer(), - // body: _buildUserList(), body: Center( child: AspectRatio( aspectRatio: 1, diff --git a/lib/pages/liked_users_page.dart b/lib/pages/liked_users_page.dart index 188bf36..d6ec45a 100644 --- a/lib/pages/liked_users_page.dart +++ b/lib/pages/liked_users_page.dart @@ -64,7 +64,8 @@ class LikedUsersPageState extends State { .get(); // Initialize _cachedMatches to keep database accesses to a minimum - bool hasMatch = await _hasMatch(swipe.swipedId); + bool hasMatch = + await UserService.hasMatch(currentUserId, swipe.swipedId); _cachedMatches[swipe.swipedId] = hasMatch; likedUsersWithSwipes.add(MapEntry(swipe, userDoc)); @@ -82,16 +83,6 @@ class LikedUsersPageState extends State { } } - Future _hasMatch(String userId) async { - DocumentSnapshot matchDoc = await FirebaseFirestore.instance - .collection(Constants.dbCollectionUsers) - .doc(currentUserId) - .collection(Constants.dbCollectionMatches) - .doc(userId) - .get(); - return matchDoc.exists; - } - Future _unlikeUser(String userId) async { try { await FirebaseFirestore.instance @@ -108,7 +99,7 @@ class LikedUsersPageState extends State { }); } catch (e) { if (mounted) { - showMsg(context, 'Error during unlike', e.toString()); + showMsg(context, 'Error undoing Like', e.toString()); } } } @@ -335,7 +326,8 @@ class LikedUsersPageState extends State { ); if (confirm == true) { - bool hasMatch = await _hasMatch(user.id); + bool hasMatch = + await UserService.hasMatch(currentUserId, user.id); if (!hasMatch) { await _unlikeUser(user.id); } else { diff --git a/lib/pages/registration_complete_page.dart b/lib/pages/registration_complete_page.dart index b95e7c6..a9024cc 100644 --- a/lib/pages/registration_complete_page.dart +++ b/lib/pages/registration_complete_page.dart @@ -1,5 +1,5 @@ -import 'package:cofounderella/components/text_bold.dart'; import 'package:flutter/material.dart'; +import '../components/text_bold.dart'; import '../services/auth/auth_gate.dart'; class RegistrationCompletePage extends StatelessWidget { diff --git a/lib/pages/user_data_page.dart b/lib/pages/user_data_page.dart index 0e43f20..122fff7 100644 --- a/lib/pages/user_data_page.dart +++ b/lib/pages/user_data_page.dart @@ -171,9 +171,8 @@ class _UserDataPageState extends State { }); } - Future saveUserData(BuildContext context) async { + Future _saveUserData(BuildContext context) async { try { - // Get userID from auth service String currentUserID = _authService.getCurrentUser()!.uid; // Get references to the current users Firebase collections @@ -260,7 +259,7 @@ class _UserDataPageState extends State { List languageCodes = _selectedLanguages.map((language) => language.code).toList(); // Clean up languages that were not part of the provided list - await deleteUnusedDocuments(languagesRef, languageCodes); + await _deleteUnusedDocuments(languagesRef, languageCodes); } return true; @@ -271,7 +270,7 @@ class _UserDataPageState extends State { } /// Deletes documents from collection that are not part of the provided list - Future deleteUnusedDocuments( + Future _deleteUnusedDocuments( CollectionReference refCollection, List idsToKeep) async { // Fetch the existing documents from the database QuerySnapshot snapshot = await refCollection.get(); @@ -286,7 +285,7 @@ class _UserDataPageState extends State { } } - void updateSelectedGender(Set newSelection) { + void _updateSelectedGender(Set newSelection) { setState(() { // By default there is only a single segment that can be // selected at one time, so its value is always the first @@ -323,7 +322,7 @@ class _UserDataPageState extends State { } void _saveButtonClicked(BuildContext context) async { - bool success = await saveUserData(context); + bool success = await _saveUserData(context); if (context.mounted) { if (success) { if (widget.isRegProcess) { @@ -534,7 +533,7 @@ class _UserDataPageState extends State { ], selected: {genderView}, showSelectedIcon: false, - onSelectionChanged: updateSelectedGender, + onSelectionChanged: _updateSelectedGender, ), ), const SizedBox(height: 20), diff --git a/lib/services/auth/auth_service.dart b/lib/services/auth/auth_service.dart index eb107c7..ea65860 100644 --- a/lib/services/auth/auth_service.dart +++ b/lib/services/auth/auth_service.dart @@ -1,7 +1,7 @@ import 'package:firebase_auth/firebase_auth.dart'; class AuthService { - // instance of auth and firestore + // instance of auth final FirebaseAuth _auth = FirebaseAuth.instance; // get current user diff --git a/lib/services/user_service.dart b/lib/services/user_service.dart index e1a9666..c76eebc 100644 --- a/lib/services/user_service.dart +++ b/lib/services/user_service.dart @@ -207,23 +207,21 @@ class UserService { return result; } - // get users stream + /// Get users stream static Stream>> getUsersStream() { return FirebaseFirestore.instance .collection(Constants.dbCollectionUsers) .snapshots() .map((snapshot) { return snapshot.docs.map((doc) { - // iterate each user + // iterate and return each user final user = doc.data(); - - //return user return user; }).toList(); }); } - // Get list of matched user ids for a given user + /// Get list of matched user ids for a given [userId] static Future> getMatchedUserIds(String userId) async { List matchedUserIds = []; @@ -235,19 +233,16 @@ class UserService { for (var doc in snapshot.docs) { final data = doc.data(); - final otherUserId = data['otherUserId'] as String?; + String? otherUserId = data['otherUserId']; if (otherUserId != null && otherUserId.isNotEmpty) { matchedUserIds.add(otherUserId); } - // assuming the match document ID is the matched user's ID - // it would just be an one liner: - // matchedUserIds.add(doc.id); } return matchedUserIds; } - // Get matched users data for a given user as stream + /// Get matched users data for a given [userId] as stream static Stream>> getMatchedUsersStream( String userId) { return FirebaseFirestore.instance @@ -273,4 +268,20 @@ class UserService { return matchedUsersSnapshot.docs.map((doc) => doc.data()).toList(); }); } + + /// Checks if a match between currentUser and [userId] exists. + /// Returns false in case of an error. + static Future hasMatch(String currentUserId, String userId) async { + try { + DocumentSnapshot matchDoc = await FirebaseFirestore.instance + .collection(Constants.dbCollectionUsers) + .doc(currentUserId) + .collection(Constants.dbCollectionMatches) + .doc(userId) + .get(); + return matchDoc.exists; + } catch (e) { + return false; + } + } }