Refresh User Current

pull/32/head
Emre KARTAL 2 years ago
parent 99932c9e2c
commit 10b947cb4e

@ -65,7 +65,7 @@ class _EditablePostComponentState extends State<EditablePostComponent> with Tick
try { try {
final image = await ImagePicker().pickImage( final image = await ImagePicker().pickImage(
source: source, source: source,
imageQuality: 10 imageQuality: 20
); );
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);

@ -20,7 +20,7 @@ class StatisticsComponent extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
AutoSizeText( AutoSizeText(
user.followed.toString(), user.followed.length.toString(),
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -40,7 +40,7 @@ class StatisticsComponent extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
AutoSizeText( AutoSizeText(
user.followers.toString(), user.followers.length.toString(),
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,

@ -237,6 +237,7 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
flex: 1, flex: 1,
child: GestureDetector( child: GestureDetector(
onTap: () async { onTap: () async {
await MyApp.userViewModel.updateUserCurrent();
bool returnFromOtherPage = await Navigator.of(context).push(routeProfile()); bool returnFromOtherPage = await Navigator.of(context).push(routeProfile());
if (returnFromOtherPage == true) { if (returnFromOtherPage == true) {
checkAvailable(); checkAvailable();

@ -5,14 +5,13 @@ class User {
String _country; String _country;
String _mail; String _mail;
String _pp; String _pp;
int _followers; List<String> _followers;
int _capsules; int _capsules;
int _followed; List<String> _followed;
List<User> friends = [];
// Constructor // Constructor
User(this._id, this._pseudo, this._uniquePseudo, this._country, this._mail, this._pp, User(this._id, this._pseudo, this._uniquePseudo, this._country, this._mail,
this._followers, this._capsules, this._followed, this.friends); this._pp, this._followers, this._capsules, this._followed);
//Getters and setters //Getters and setters
String get id => _id; String get id => _id;
@ -53,15 +52,15 @@ class User {
_capsules = value; _capsules = value;
} }
int get followed => _followed; List<String> get followed => _followed;
set followed(int value) { set followed(List<String> value) {
_followed = value; _followed = value;
} }
int get followers => _followers; List<String> get followers => _followers;
set followers(int value) { set followers(List<String> value) {
_followers = value; _followers = value;
} }
} }

@ -12,10 +12,9 @@ class UserMapper {
data?["country"] ?? "", data?["country"] ?? "",
data?["mail"], data?["mail"],
data?["picture"], data?["picture"],
data?["followers"] ?? 0, List<String>.from(data?["followers"] as List),
data?["nbCapsules"] ?? 0, data?["nbCapsules"] ?? 0,
data?["followed"] ?? 0, List<String>.from(data?["followed"] as List));
data?['friends'] is List<User> ? List.from(data?['friends']) : []);
} }
/* /*
static Map<String, dynamic> toFirebase(User user) { static Map<String, dynamic> toFirebase(User user) {

@ -25,9 +25,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2UYSIpWSnX4gJhZJzaN4q.jpg?alt=media&token=39baf86a-4d19-4534-b777-1a4feca67359", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2UYSIpWSnX4gJhZJzaN4q.jpg?alt=media&token=39baf86a-4d19-4534-b777-1a4feca67359",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -35,9 +35,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -45,9 +45,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -55,9 +55,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -65,9 +65,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -75,9 +75,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -85,9 +85,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -95,9 +95,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -105,9 +105,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -115,9 +115,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -125,9 +125,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
User( User(
"&", "&",
"_pseudo", "_pseudo",
@ -135,9 +135,9 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
"_country", "_country",
"_mail", "_mail",
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/RUiGpZ8AzCQPqiVJKwuQeIqiC4B2bafPGRGLh2La72LkmQst.jpg?alt=media&token=ac1916f0-e08d-43bd-977a-2c2d94182609",
1, [],
12, 12,
23, []), []),
]; ];
Future<void> resetFullScreen() async { Future<void> resetFullScreen() async {
@ -162,8 +162,10 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
Align( Align(
child: Text( child: Text(
"Ajouter des amis", "Ajouter des amis",
style: style: GoogleFonts.plusJakartaSans(
GoogleFonts.plusJakartaSans(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold), color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.bold),
), ),
), ),
GestureDetector( GestureDetector(
@ -179,7 +181,8 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
height: 30, height: 30,
width: 30, width: 30,
child: const Image( child: const Image(
image: AssetImage("assets/images/return_icon.png"), image:
AssetImage("assets/images/return_icon.png"),
height: 8, height: 8,
), ),
))), ))),
@ -193,7 +196,8 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
child: Column( child: Column(
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.only(bottom: 20, left: 20, right: 20, top: 20), padding: const EdgeInsets.only(
bottom: 20, left: 20, right: 20, top: 20),
child: SizedBox( child: SizedBox(
height: 40, height: 40,
child: TextField( child: TextField(
@ -216,31 +220,40 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
), ),
focusedBorder: const OutlineInputBorder( focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(width: 1, color: grayColor), borderSide: BorderSide(width: 1, color: grayColor),
borderRadius: BorderRadius.all(Radius.circular(10))), borderRadius:
contentPadding: BorderRadius.all(Radius.circular(10))),
const EdgeInsets.only(top: 0, bottom: 0, left: defaultPadding, right: defaultPadding), contentPadding: const EdgeInsets.only(
top: 0,
bottom: 0,
left: defaultPadding,
right: defaultPadding),
fillColor: searchBarColor, fillColor: searchBarColor,
filled: true, filled: true,
focusColor: grayText, focusColor: grayText,
enabledBorder: const OutlineInputBorder( enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(width: 1, color: grayColor), borderSide: BorderSide(width: 1, color: grayColor),
borderRadius: BorderRadius.all(Radius.circular(10))), borderRadius:
BorderRadius.all(Radius.circular(10))),
hintText: 'Chercher un ami', hintText: 'Chercher un ami',
hintStyle: GoogleFonts.plusJakartaSans(color: grayHint)), hintStyle:
GoogleFonts.plusJakartaSans(color: grayHint)),
), ),
), ),
), ),
Flexible( Flexible(
child: ScrollConfiguration( child: ScrollConfiguration(
behavior: const ScrollBehavior().copyWith(scrollbars: true), behavior:
const ScrollBehavior().copyWith(scrollbars: true),
child: ListView.builder( child: ListView.builder(
physics: const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast), physics: const BouncingScrollPhysics(
decelerationRate: ScrollDecelerationRate.fast),
itemCount: fakeList.length, itemCount: fakeList.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return InkWell( return InkWell(
child: Padding( child: Padding(
padding: EdgeInsets.fromLTRB(20, 0, 20, 20), padding: EdgeInsets.fromLTRB(20, 0, 20, 20),
child: ProfileListComponent(user: fakeList[index])), child: ProfileListComponent(
user: fakeList[index])),
); );
}, },
))) )))

@ -17,13 +17,11 @@ class AuthService {
"pseudo": pseudo, "pseudo": pseudo,
"phone_number": "", "phone_number": "",
"unique_id": uniqueId, "unique_id": uniqueId,
"followed": 0, "followed": [],
"nbCapsules": 0, "nbCapsules": 0,
"followers": 0, "followers": [],
"picture": "picture":
"https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/justMusicDefaultImage.png?alt=media&token=020d0fcb-b7df-4d4d-b380-e99597293fcc", "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/justMusicDefaultImage.png?alt=media&token=020d0fcb-b7df-4d4d-b380-e99597293fcc"
"friends": [],
"comments": []
}; };
MyApp.db MyApp.db
@ -52,10 +50,10 @@ class AuthService {
final QuerySnapshot querySnapshot = final QuerySnapshot querySnapshot =
await usersCollection.where('pseudo', isEqualTo: pseudo).get(); await usersCollection.where('pseudo', isEqualTo: pseudo).get();
for (final doc in querySnapshot.docs) { querySnapshot.docs.forEach((snapshot) {
suffix++; suffix++;
uniqueId = '$pseudo#${suffix.toString().padLeft(4, '0')}'; uniqueId = '$pseudo#${suffix.toString().padLeft(4, '0')}';
} });
return uniqueId; return uniqueId;
} }

@ -1,8 +1,6 @@
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:intl/intl.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import 'package:firebase_storage/firebase_storage.dart'; import 'package:firebase_storage/firebase_storage.dart';
@ -43,8 +41,6 @@ class PostService {
deletePost() {} deletePost() {}
getPostsById(String id) {}
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts({int limit = 10, int offset = 0}) async { Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts({int limit = 10, int offset = 0}) async {
DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24)); DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24));
Timestamp twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo); Timestamp twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo);
@ -68,7 +64,6 @@ class PostService {
QuerySnapshot<Map<String, dynamic>> response = QuerySnapshot<Map<String, dynamic>> response =
await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get(); await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get();
// Utiliser any() pour vérifier s'il y a au moins un document avec la date d'aujourd'hui
bool isTodayAvailable = response.docs.any((doc) { bool isTodayAvailable = response.docs.any((doc) {
DateTime date = doc["date"].toDate(); // Assuming the field name is "date" DateTime date = doc["date"].toDate(); // Assuming the field name is "date"
return date.day == today.day && date.month == today.month && date.year == today.year; return date.day == today.day && date.month == today.month && date.year == today.year;

@ -42,6 +42,19 @@ class UserViewModel {
return alphaNumericRegExp.hasMatch(input); return alphaNumericRegExp.hasMatch(input);
} }
updateUserCurrent() async {
try {
final user = await MyApp.db
.collection("users")
.doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid)
.get();
User data = UserMapper.toModel(user, null);
_userCurrent = data;
} catch (e) {
print(e);
}
}
register(String pseudo, String password, String email) async { register(String pseudo, String password, String email) async {
if (!_isAlphaNumeric(pseudo)) { if (!_isAlphaNumeric(pseudo)) {
throw ("Le pseudo doit contenir seulement des lettres et des chiffres"); throw ("Le pseudo doit contenir seulement des lettres et des chiffres");

Loading…
Cancel
Save