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

View File

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

View File

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

View File

@ -1,4 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cofounderella/constants.dart';
import 'package:cofounderella/models/message.dart'; import 'package:cofounderella/models/message.dart';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
@ -9,7 +10,10 @@ class ChatService {
// get user stream // get user stream
Stream<List<Map<String, dynamic>>> getUsersStream() { 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) { return snapshot.docs.map((doc) {
// iterate each user // iterate each user
final user = doc.data(); final user = doc.data();
@ -43,9 +47,9 @@ class ChatService {
// add new message to database // add new message to database
await _firestore await _firestore
.collection("chat_rooms") .collection(Constants.dbCollectionChatRooms)
.doc(chatRoomID) .doc(chatRoomID)
.collection("messages") .collection(Constants.dbCollectionMessages)
.add(newMessage.toMap()); .add(newMessage.toMap());
} }
@ -58,9 +62,9 @@ class ChatService {
String chatRoomID = ids.join('_'); String chatRoomID = ids.join('_');
return _firestore return _firestore
.collection("chat_rooms") .collection(Constants.dbCollectionChatRooms)
.doc(chatRoomID) .doc(chatRoomID)
.collection("messages") .collection(Constants.dbCollectionMessages)
.orderBy("timestamp", descending: false) .orderBy("timestamp", descending: false)
.snapshots(); .snapshots();
} }