recap component
continuous-integration/drone/push Build is passing Details

PROFIL_PAGE_LDE
Lucas Delanier 2 years ago
parent b502084aff
commit eb551aefa9

@ -1,12 +1,18 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/Material.dart'; import 'package:flutter/Material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import '../main.dart';
import '../model/User.dart' as justMusic;
import '../values/constants.dart'; import '../values/constants.dart';
import 'little_post_recap_component.dart'; import 'little_post_recap_component.dart';
import 'package:intl/intl.dart';
class RecapComponent extends StatelessWidget { class RecapComponent extends StatelessWidget {
const RecapComponent({super.key}); final justMusic.User user;
const RecapComponent({super.key, required this.user});
Future<List<bool>>? _fetchdata() async {
return await MyApp.postViewModel.recapSevenDays(user.id);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -85,25 +91,33 @@ class RecapComponent extends StatelessWidget {
], ],
), ),
)), )),
Padding( FutureBuilder<List<bool>>(
future: _fetchdata(), // a previously-obtained Future<String> or null
builder: (BuildContext context, AsyncSnapshot<List<bool>> snapshot) {
if (snapshot.hasData) {
return Padding(
padding: EdgeInsets.all(12), padding: EdgeInsets.all(12),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
LittleCapsule( LittleCapsule(
isEmpty: false, isEmpty: snapshot.data![0],
date: DateTime.now(), date: currentDate.subtract(const Duration(days: 6)),
), ),
LittleCapsule(isEmpty: true, date: currentDate.subtract(const Duration(days: 5))), LittleCapsule(isEmpty: snapshot.data![1], date: currentDate.subtract(const Duration(days: 5))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 4))), LittleCapsule(isEmpty: snapshot.data![2], date: currentDate.subtract(const Duration(days: 4))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 3))), LittleCapsule(isEmpty: snapshot.data![3], date: currentDate.subtract(const Duration(days: 3))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 2))), LittleCapsule(isEmpty: snapshot.data![4], date: currentDate.subtract(const Duration(days: 2))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 1))), LittleCapsule(isEmpty: snapshot.data![5], date: currentDate.subtract(const Duration(days: 1))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 0))), LittleCapsule(isEmpty: snapshot.data![6], date: currentDate.subtract(const Duration(days: 0))),
], ],
), ),
) );
} else {
return Container();
}
}),
], ],
), ),
); );

@ -9,7 +9,9 @@ class SettingPartComponent extends StatelessWidget {
final JustMusicIcon icon; final JustMusicIcon icon;
final String label; final String label;
final bool important; final bool important;
const SettingPartComponent({Key? key, required this.icon, required this.label, this.important = false}) final VoidCallback? action;
const SettingPartComponent(
{Key? key, required this.icon, required this.label, this.important = false, required this.action})
: super(key: key); : super(key: key);
@override @override
@ -24,11 +26,7 @@ class SettingPartComponent extends StatelessWidget {
color: important ? warningBttnColor : settingColor, color: important ? warningBttnColor : settingColor,
borderOnForeground: false, borderOnForeground: false,
child: InkWell( child: InkWell(
onTap: () { onTap: action,
if (icon == JustMusicIcon.cross) {
logout();
}
},
splashColor: Colors.transparent, splashColor: Colors.transparent,
highlightColor: Colors.white.withOpacity(0.08), highlightColor: Colors.white.withOpacity(0.08),
child: Container( child: Container(

@ -1,3 +1,4 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -5,6 +6,7 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:justmusic/values/icons.dart'; import 'package:justmusic/values/icons.dart';
import '../components/profile_component.dart'; import '../components/profile_component.dart';
import '../components/setting_part_component.dart'; import '../components/setting_part_component.dart';
import '../config/routes.dart';
import '../main.dart'; import '../main.dart';
import '../values/constants.dart'; import '../values/constants.dart';
@ -18,6 +20,16 @@ class ProfileScreen extends StatefulWidget {
class _ProfileScreenState extends State<ProfileScreen> { class _ProfileScreenState extends State<ProfileScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Future<void> logout() async {
print("cc");
await FirebaseAuth.instance.signOut();
Navigator.pushNamed(context, '/welcome');
}
void _openDetail() {
Navigator.of(context).push(routeUser(MyApp.userViewModel.userCurrent));
}
return Scaffold( return Scaffold(
appBar: PreferredSize( appBar: PreferredSize(
preferredSize: Size(double.infinity, 58), preferredSize: Size(double.infinity, 58),
@ -84,23 +96,28 @@ class _ProfileScreenState extends State<ProfileScreen> {
SettingPartComponent( SettingPartComponent(
icon: JustMusicIcon.profile, icon: JustMusicIcon.profile,
label: 'Compte', label: 'Compte',
action: _openDetail,
), ),
SettingPartComponent( const SettingPartComponent(
icon: JustMusicIcon.history, icon: JustMusicIcon.history,
label: 'Historiques des capsules', label: 'Historiques des capsules',
action: null,
), ),
SettingPartComponent( const SettingPartComponent(
icon: JustMusicIcon.spotify, icon: JustMusicIcon.spotify,
label: 'Lier un compte Spotify', label: 'Lier un compte Spotify',
action: null,
), ),
SettingPartComponent( const SettingPartComponent(
icon: JustMusicIcon.trash, icon: JustMusicIcon.trash,
label: 'Supprimer mon compte', label: 'Supprimer mon compte',
action: null,
), ),
SettingPartComponent( SettingPartComponent(
icon: JustMusicIcon.cross, icon: JustMusicIcon.cross,
label: 'Déconnexion', label: 'Déconnexion',
important: true, important: true,
action: logout,
), ),
], ],
), ),
@ -114,15 +131,17 @@ class _ProfileScreenState extends State<ProfileScreen> {
), ),
ClipRRect( ClipRRect(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
child: Column( child: const Column(
children: const [ children: [
SettingPartComponent( SettingPartComponent(
icon: JustMusicIcon.theme, icon: JustMusicIcon.theme,
label: 'Thême de l\'application', label: 'Thême de l\'application',
action: null,
), ),
SettingPartComponent( SettingPartComponent(
icon: JustMusicIcon.notification, icon: JustMusicIcon.notification,
label: 'Notifications', label: 'Notifications',
action: null,
), ),
], ],
), ),

@ -73,7 +73,8 @@ class _UserScreenState extends State<UserScreen> {
padding: EdgeInsets.only(top: 68.h, bottom: 40), padding: EdgeInsets.only(top: 68.h, bottom: 40),
child: ProfileComponent(user: widget.user), child: ProfileComponent(user: widget.user),
), ),
Align( MyApp.userViewModel.userCurrent.id != widget.user.id
? Align(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
child: isClicked child: isClicked
? SizedBox( ? SizedBox(
@ -140,11 +141,12 @@ class _UserScreenState extends State<UserScreen> {
color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)), color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)),
), ),
)))), )))),
), )
: Container(),
SizedBox( SizedBox(
height: 40, height: 40,
), ),
RecapComponent() RecapComponent(user: widget.user)
], ],
), ),
), ),

@ -7,8 +7,7 @@ import 'package:firebase_storage/firebase_storage.dart';
import '../main.dart'; import '../main.dart';
class PostService { class PostService {
createPost(String? description, String idMusic, File? image, createPost(String? description, String idMusic, File? image, Tuple2<String, String>? location) async {
Tuple2<String, String>? location) async {
var id = MyApp.userViewModel.userCurrent.id; var id = MyApp.userViewModel.userCurrent.id;
final post = <String, dynamic>{ final post = <String, dynamic>{
"user_id": id, "user_id": id,
@ -42,14 +41,11 @@ class PostService {
deletePost() {} deletePost() {}
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts( Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts({int limit = 10, int offset = 0}) async {
{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 twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo);
Timestamp.fromDate(twentyFourHoursAgo);
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore.instance
.instance
.collection("posts") .collection("posts")
.where("date", isGreaterThan: twentyFourHoursAgoTimestamp) .where("date", isGreaterThan: twentyFourHoursAgoTimestamp)
.limit(limit) .limit(limit)
@ -67,8 +63,7 @@ class PostService {
return Timestamp.fromDate(twentyFourHoursAgo); return Timestamp.fromDate(twentyFourHoursAgo);
} }
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPostsFriends( Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPostsFriends({int limit = 10, int offset = 0}) async {
{int limit = 10, int offset = 0}) async {
var timestamp = _getTwentyFourHoursAgoTimestamp(); var timestamp = _getTwentyFourHoursAgoTimestamp();
var response = await FirebaseFirestore.instance var response = await FirebaseFirestore.instance
.collection("posts") .collection("posts")
@ -84,17 +79,12 @@ class PostService {
Future<bool> getAvailable(String idUser) async { Future<bool> getAvailable(String idUser) async {
DateTime today = DateTime.now(); DateTime today = DateTime.now();
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore QuerySnapshot<Map<String, dynamic>> response =
.instance await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get();
.collection("posts")
.where("user_id", isEqualTo: idUser)
.get();
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 && return date.day == today.day && date.month == today.month && date.year == today.year;
date.month == today.month &&
date.year == today.year;
}); });
return !isTodayAvailable; return !isTodayAvailable;
@ -103,17 +93,13 @@ class PostService {
Future<List<bool>> recapSevenDays(String id) async { Future<List<bool>> recapSevenDays(String id) async {
List<bool> recapList = []; List<bool> recapList = [];
DateTime sevenDaysAgo = DateTime.now().subtract(Duration(days: 7)); DateTime sevenDaysAgo = DateTime.now().subtract(Duration(days: 6));
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore QuerySnapshot<Map<String, dynamic>> response =
.instance await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: id).get();
.collection("posts")
.where("user_id", isEqualTo: id)
.get();
List<Map<String, dynamic>?> postList = response.docs List<Map<String, dynamic>?> postList =
.map((DocumentSnapshot<Map<String, dynamic>> doc) => doc.data()) response.docs.map((DocumentSnapshot<Map<String, dynamic>> doc) => doc.data()).toList();
.toList();
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
DateTime date = sevenDaysAgo.add(Duration(days: i)); DateTime date = sevenDaysAgo.add(Duration(days: i));

Loading…
Cancel
Save