constants.dart
parent
25f456a193
commit
cccfcb5a3c
|
@ -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';
|
||||
}
|
|
@ -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(),
|
||||
);
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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,
|
||||
|
@ -53,6 +57,4 @@ class AuthService {
|
|||
Future<void> signOut() async {
|
||||
return await _auth.signOut();
|
||||
}
|
||||
|
||||
// errors
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
@ -43,9 +47,9 @@ class ChatService {
|
|||
|
||||
// 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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue