Code formatting

master
Rafael 2024-06-17 20:39:56 +02:00
parent 16ae60b7d4
commit 489f1139b5
8 changed files with 41 additions and 38 deletions

View File

@ -95,8 +95,9 @@ class _ChatPageState extends State<ChatPage> {
Widget chatHeader = Text(widget.chatTitle); Widget chatHeader = Text(widget.chatTitle);
Widget? userPic; Widget? userPic;
if (widget.profileImageUrl != null && widget.profileImageUrl!.isNotEmpty) { if (widget.profileImageUrl != null && widget.profileImageUrl!.isNotEmpty) {
userPic = userPic = CircleAvatar(
CircleAvatar(backgroundImage: NetworkImage(widget.profileImageUrl!)); backgroundImage: NetworkImage(widget.profileImageUrl!),
);
} }
if (userPic != null) { if (userPic != null) {
chatHeader = Row( chatHeader = Row(

View File

@ -45,8 +45,6 @@ class EditProfilePageState extends State<EditProfilePage> {
if (pickedFile != null) { if (pickedFile != null) {
CroppedFile? croppedFile = await ImageCropper().cropImage( CroppedFile? croppedFile = await ImageCropper().cropImage(
sourcePath: pickedFile.path, sourcePath: pickedFile.path,
//compressFormat: ImageCompressFormat.jpg,
//compressQuality: 100,
aspectRatioPresets: [ aspectRatioPresets: [
CropAspectRatioPreset.square, CropAspectRatioPreset.square,
CropAspectRatioPreset.ratio3x2, CropAspectRatioPreset.ratio3x2,
@ -75,7 +73,10 @@ class EditProfilePageState extends State<EditProfilePage> {
height: 400, height: 400,
), ),
viewPort: const CroppieViewPort( viewPort: const CroppieViewPort(
width: 360, height: 360, type: 'circle'), width: 360,
height: 360,
type: 'circle',
),
enableExif: true, enableExif: true,
enableZoom: true, enableZoom: true,
showZoomer: true, showZoomer: true,

View File

@ -14,7 +14,6 @@ class HomePage extends StatelessWidget {
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
), ),
drawer: const MyDrawer(), drawer: const MyDrawer(),
// body: _buildUserList(),
body: Center( body: Center(
child: AspectRatio( child: AspectRatio(
aspectRatio: 1, aspectRatio: 1,

View File

@ -64,7 +64,8 @@ class LikedUsersPageState extends State<LikedUsersPage> {
.get(); .get();
// Initialize _cachedMatches to keep database accesses to a minimum // 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; _cachedMatches[swipe.swipedId] = hasMatch;
likedUsersWithSwipes.add(MapEntry(swipe, userDoc)); 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 { Future<void> _unlikeUser(String userId) async {
try { try {
await FirebaseFirestore.instance await FirebaseFirestore.instance
@ -108,7 +99,7 @@ class LikedUsersPageState extends State<LikedUsersPage> {
}); });
} catch (e) { } catch (e) {
if (mounted) { 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) { if (confirm == true) {
bool hasMatch = await _hasMatch(user.id); bool hasMatch =
await UserService.hasMatch(currentUserId, user.id);
if (!hasMatch) { if (!hasMatch) {
await _unlikeUser(user.id); await _unlikeUser(user.id);
} else { } else {

View File

@ -1,5 +1,5 @@
import 'package:cofounderella/components/text_bold.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../components/text_bold.dart';
import '../services/auth/auth_gate.dart'; import '../services/auth/auth_gate.dart';
class RegistrationCompletePage extends StatelessWidget { class RegistrationCompletePage extends StatelessWidget {

View File

@ -171,9 +171,8 @@ class _UserDataPageState extends State<UserDataPage> {
}); });
} }
Future<bool> saveUserData(BuildContext context) async { Future<bool> _saveUserData(BuildContext context) async {
try { try {
// Get userID from auth service
String currentUserID = _authService.getCurrentUser()!.uid; String currentUserID = _authService.getCurrentUser()!.uid;
// Get references to the current users Firebase collections // Get references to the current users Firebase collections
@ -260,7 +259,7 @@ class _UserDataPageState extends State<UserDataPage> {
List<String> languageCodes = List<String> languageCodes =
_selectedLanguages.map((language) => language.code).toList(); _selectedLanguages.map((language) => language.code).toList();
// Clean up languages that were not part of the provided list // Clean up languages that were not part of the provided list
await deleteUnusedDocuments(languagesRef, languageCodes); await _deleteUnusedDocuments(languagesRef, languageCodes);
} }
return true; return true;
@ -271,7 +270,7 @@ class _UserDataPageState extends State<UserDataPage> {
} }
/// Deletes documents from collection that are not part of the provided list /// Deletes documents from collection that are not part of the provided list
Future<void> deleteUnusedDocuments( Future<void> _deleteUnusedDocuments(
CollectionReference refCollection, List<String> idsToKeep) async { CollectionReference refCollection, List<String> idsToKeep) async {
// Fetch the existing documents from the database // Fetch the existing documents from the database
QuerySnapshot snapshot = await refCollection.get(); 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(() { setState(() {
// By default there is only a single segment that can be // By default there is only a single segment that can be
// selected at one time, so its value is always the first // 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 { void _saveButtonClicked(BuildContext context) async {
bool success = await saveUserData(context); bool success = await _saveUserData(context);
if (context.mounted) { if (context.mounted) {
if (success) { if (success) {
if (widget.isRegProcess) { if (widget.isRegProcess) {
@ -534,7 +533,7 @@ class _UserDataPageState extends State<UserDataPage> {
], ],
selected: <Gender>{genderView}, selected: <Gender>{genderView},
showSelectedIcon: false, showSelectedIcon: false,
onSelectionChanged: updateSelectedGender, onSelectionChanged: _updateSelectedGender,
), ),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),

View File

@ -1,7 +1,7 @@
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
class AuthService { class AuthService {
// instance of auth and firestore // instance of auth
final FirebaseAuth _auth = FirebaseAuth.instance; final FirebaseAuth _auth = FirebaseAuth.instance;
// get current user // get current user

View File

@ -207,23 +207,21 @@ class UserService {
return result; return result;
} }
// get users stream /// Get users stream
static Stream<List<Map<String, dynamic>>> getUsersStream() { static Stream<List<Map<String, dynamic>>> getUsersStream() {
return FirebaseFirestore.instance return FirebaseFirestore.instance
.collection(Constants.dbCollectionUsers) .collection(Constants.dbCollectionUsers)
.snapshots() .snapshots()
.map((snapshot) { .map((snapshot) {
return snapshot.docs.map((doc) { return snapshot.docs.map((doc) {
// iterate each user // iterate and return each user
final user = doc.data(); final user = doc.data();
//return user
return user; return user;
}).toList(); }).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 { static Future<List<String>> getMatchedUserIds(String userId) async {
List<String> matchedUserIds = []; List<String> matchedUserIds = [];
@ -235,19 +233,16 @@ class UserService {
for (var doc in snapshot.docs) { for (var doc in snapshot.docs) {
final data = doc.data(); final data = doc.data();
final otherUserId = data['otherUserId'] as String?; String? otherUserId = data['otherUserId'];
if (otherUserId != null && otherUserId.isNotEmpty) { if (otherUserId != null && otherUserId.isNotEmpty) {
matchedUserIds.add(otherUserId); 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; 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( static Stream<List<Map<String, dynamic>>> getMatchedUsersStream(
String userId) { String userId) {
return FirebaseFirestore.instance return FirebaseFirestore.instance
@ -273,4 +268,20 @@ class UserService {
return matchedUsersSnapshot.docs.map((doc) => doc.data()).toList(); 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;
}
}
} }