Code formatting
parent
16ae60b7d4
commit
489f1139b5
|
@ -95,8 +95,9 @@ class _ChatPageState extends State<ChatPage> {
|
|||
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(
|
||||
|
|
|
@ -45,8 +45,6 @@ class EditProfilePageState extends State<EditProfilePage> {
|
|||
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<EditProfilePage> {
|
|||
height: 400,
|
||||
),
|
||||
viewPort: const CroppieViewPort(
|
||||
width: 360, height: 360, type: 'circle'),
|
||||
width: 360,
|
||||
height: 360,
|
||||
type: 'circle',
|
||||
),
|
||||
enableExif: true,
|
||||
enableZoom: true,
|
||||
showZoomer: true,
|
||||
|
|
|
@ -14,7 +14,6 @@ class HomePage extends StatelessWidget {
|
|||
backgroundColor: Colors.transparent,
|
||||
),
|
||||
drawer: const MyDrawer(),
|
||||
// body: _buildUserList(),
|
||||
body: Center(
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
|
|
|
@ -64,7 +64,8 @@ class LikedUsersPageState extends State<LikedUsersPage> {
|
|||
.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<LikedUsersPage> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> _hasMatch(String userId) async {
|
||||
DocumentSnapshot matchDoc = await FirebaseFirestore.instance
|
||||
.collection(Constants.dbCollectionUsers)
|
||||
.doc(currentUserId)
|
||||
.collection(Constants.dbCollectionMatches)
|
||||
.doc(userId)
|
||||
.get();
|
||||
return matchDoc.exists;
|
||||
}
|
||||
|
||||
Future<void> _unlikeUser(String userId) async {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
|
@ -108,7 +99,7 @@ class LikedUsersPageState extends State<LikedUsersPage> {
|
|||
});
|
||||
} 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<LikedUsersPage> {
|
|||
);
|
||||
|
||||
if (confirm == true) {
|
||||
bool hasMatch = await _hasMatch(user.id);
|
||||
bool hasMatch =
|
||||
await UserService.hasMatch(currentUserId, user.id);
|
||||
if (!hasMatch) {
|
||||
await _unlikeUser(user.id);
|
||||
} else {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -171,9 +171,8 @@ class _UserDataPageState extends State<UserDataPage> {
|
|||
});
|
||||
}
|
||||
|
||||
Future<bool> saveUserData(BuildContext context) async {
|
||||
Future<bool> _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<UserDataPage> {
|
|||
List<String> 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<UserDataPage> {
|
|||
}
|
||||
|
||||
/// Deletes documents from collection that are not part of the provided list
|
||||
Future<void> deleteUnusedDocuments(
|
||||
Future<void> _deleteUnusedDocuments(
|
||||
CollectionReference refCollection, List<String> idsToKeep) async {
|
||||
// Fetch the existing documents from the database
|
||||
QuerySnapshot snapshot = await refCollection.get();
|
||||
|
@ -286,7 +285,7 @@ class _UserDataPageState extends State<UserDataPage> {
|
|||
}
|
||||
}
|
||||
|
||||
void updateSelectedGender(Set<Gender> newSelection) {
|
||||
void _updateSelectedGender(Set<Gender> 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<UserDataPage> {
|
|||
}
|
||||
|
||||
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<UserDataPage> {
|
|||
],
|
||||
selected: <Gender>{genderView},
|
||||
showSelectedIcon: false,
|
||||
onSelectionChanged: updateSelectedGender,
|
||||
onSelectionChanged: _updateSelectedGender,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -207,23 +207,21 @@ class UserService {
|
|||
return result;
|
||||
}
|
||||
|
||||
// get users stream
|
||||
/// Get users stream
|
||||
static Stream<List<Map<String, dynamic>>> 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<List<String>> getMatchedUserIds(String userId) async {
|
||||
List<String> 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<List<Map<String, dynamic>>> 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<bool> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue