constants.dart

master
Rafael 2024-05-05 10:26:49 +02:00
parent 25f456a193
commit cccfcb5a3c
5 changed files with 32 additions and 13 deletions

11
lib/constants.dart 100644
View File

@ -0,0 +1,11 @@
class Constants {
Constants._();
/// Title of the app
static const String appTitle = "Cofounderella";
static const String dbCollectionUsers = 'Users';
static const String dbCollectionLanguages = 'languages';
static const String dbCollectionChatRooms = 'chat_rooms';
static const String dbCollectionMessages = 'messages';
}

View File

@ -1,3 +1,4 @@
import 'package:cofounderella/constants.dart';
import 'package:cofounderella/services/auth/auth_gate.dart';
import 'package:cofounderella/themes/theme_provider.dart';
import 'package:flutter/material.dart';
@ -28,7 +29,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Cofounderella',
title: Constants.appTitle,
theme: Provider.of<ThemeProvider>(context).themeData,
home: const AuthGate(),
);

View File

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cofounderella/components/my_button.dart';
import 'package:cofounderella/components/my_textfield.dart';
import 'package:cofounderella/constants.dart';
import 'package:cofounderella/models/language.dart';
import 'package:cofounderella/models/language_setting.dart';
import 'package:flutter/material.dart';
@ -41,9 +42,9 @@ class _UserDataPageState extends State<UserDataPage> {
// Get reference to the Firebase collection
CollectionReference languagesRef = _firestore
.collection('Users')
.collection(Constants.dbCollectionUsers)
.doc(currentUserID)
.collection('languages');
.collection(Constants.dbCollectionLanguages);
// Loop through each Language object and save it to the collection
for (int i = 0; i < _selectedLanguages.length; i++) {

View File

@ -1,4 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cofounderella/constants.dart';
import 'package:firebase_auth/firebase_auth.dart';
class AuthService {
@ -36,7 +37,10 @@ class AuthService {
);
// save user info in a document
_firestore.collection("Users").doc(userCredential.user!.uid).set(
_firestore
.collection(Constants.dbCollectionUsers)
.doc(userCredential.user!.uid)
.set(
{
'uid': userCredential.user!.uid,
'email': email,
@ -49,10 +53,8 @@ class AuthService {
}
}
// sign out
// sign out
Future<void> signOut() async {
return await _auth.signOut();
}
// errors
}

View File

@ -1,4 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cofounderella/constants.dart';
import 'package:cofounderella/models/message.dart';
import 'package:firebase_auth/firebase_auth.dart';
@ -9,7 +10,10 @@ class ChatService {
// get user stream
Stream<List<Map<String, dynamic>>> getUsersStream() {
return _firestore.collection("Users").snapshots().map((snapshot) {
return _firestore
.collection(Constants.dbCollectionUsers)
.snapshots()
.map((snapshot) {
return snapshot.docs.map((doc) {
// iterate each user
final user = doc.data();
@ -41,11 +45,11 @@ class ChatService {
ids.sort(); // sort to ensure the chatroomID is the same for any 2 users
String chatRoomID = ids.join('_');
// add new message to database
// add new message to database
await _firestore
.collection("chat_rooms")
.collection(Constants.dbCollectionChatRooms)
.doc(chatRoomID)
.collection("messages")
.collection(Constants.dbCollectionMessages)
.add(newMessage.toMap());
}
@ -58,9 +62,9 @@ class ChatService {
String chatRoomID = ids.join('_');
return _firestore
.collection("chat_rooms")
.collection(Constants.dbCollectionChatRooms)
.doc(chatRoomID)
.collection("messages")
.collection(Constants.dbCollectionMessages)
.orderBy("timestamp", descending: false)
.snapshots();
}