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:google_fonts/google_fonts.dart';
import '../main.dart';
import '../model/User.dart' as justMusic;
import '../values/constants.dart';
import 'little_post_recap_component.dart';
import 'package:intl/intl.dart';
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
Widget build(BuildContext context) {
@ -85,25 +91,33 @@ class RecapComponent extends StatelessWidget {
],
),
)),
Padding(
padding: EdgeInsets.all(12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
LittleCapsule(
isEmpty: false,
date: DateTime.now(),
),
LittleCapsule(isEmpty: true, date: currentDate.subtract(const Duration(days: 5))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 4))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 3))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 2))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 1))),
LittleCapsule(isEmpty: false, date: currentDate.subtract(const Duration(days: 0))),
],
),
)
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),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
LittleCapsule(
isEmpty: snapshot.data![0],
date: currentDate.subtract(const Duration(days: 6)),
),
LittleCapsule(isEmpty: snapshot.data![1], date: currentDate.subtract(const Duration(days: 5))),
LittleCapsule(isEmpty: snapshot.data![2], date: currentDate.subtract(const Duration(days: 4))),
LittleCapsule(isEmpty: snapshot.data![3], date: currentDate.subtract(const Duration(days: 3))),
LittleCapsule(isEmpty: snapshot.data![4], date: currentDate.subtract(const Duration(days: 2))),
LittleCapsule(isEmpty: snapshot.data![5], date: currentDate.subtract(const Duration(days: 1))),
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 String label;
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);
@override
@ -24,11 +26,7 @@ class SettingPartComponent extends StatelessWidget {
color: important ? warningBttnColor : settingColor,
borderOnForeground: false,
child: InkWell(
onTap: () {
if (icon == JustMusicIcon.cross) {
logout();
}
},
onTap: action,
splashColor: Colors.transparent,
highlightColor: Colors.white.withOpacity(0.08),
child: Container(

@ -1,3 +1,4 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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 '../components/profile_component.dart';
import '../components/setting_part_component.dart';
import '../config/routes.dart';
import '../main.dart';
import '../values/constants.dart';
@ -18,6 +20,16 @@ class ProfileScreen extends StatefulWidget {
class _ProfileScreenState extends State<ProfileScreen> {
@override
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(
appBar: PreferredSize(
preferredSize: Size(double.infinity, 58),
@ -84,23 +96,28 @@ class _ProfileScreenState extends State<ProfileScreen> {
SettingPartComponent(
icon: JustMusicIcon.profile,
label: 'Compte',
action: _openDetail,
),
SettingPartComponent(
const SettingPartComponent(
icon: JustMusicIcon.history,
label: 'Historiques des capsules',
action: null,
),
SettingPartComponent(
const SettingPartComponent(
icon: JustMusicIcon.spotify,
label: 'Lier un compte Spotify',
action: null,
),
SettingPartComponent(
const SettingPartComponent(
icon: JustMusicIcon.trash,
label: 'Supprimer mon compte',
action: null,
),
SettingPartComponent(
icon: JustMusicIcon.cross,
label: 'Déconnexion',
important: true,
action: logout,
),
],
),
@ -114,15 +131,17 @@ class _ProfileScreenState extends State<ProfileScreen> {
),
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Column(
children: const [
child: const Column(
children: [
SettingPartComponent(
icon: JustMusicIcon.theme,
label: 'Thême de l\'application',
action: null,
),
SettingPartComponent(
icon: JustMusicIcon.notification,
label: 'Notifications',
action: null,
),
],
),

@ -73,78 +73,80 @@ class _UserScreenState extends State<UserScreen> {
padding: EdgeInsets.only(top: 68.h, bottom: 40),
child: ProfileComponent(user: widget.user),
),
Align(
alignment: Alignment.topCenter,
child: isClicked
? SizedBox(
// Définir une largeur minimale pour le bouton "Ajouter"
width: 120, // Réglez cette valeur en fonction de vos besoins
child: Material(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: selectedButton,
child: InkWell(
splashColor: Colors.white.withOpacity(0.3),
onTap: () async {
await MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Vous ne suivez plus ${widget.user.pseudo}",
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w400, fontSize: 20.h),
),
backgroundColor: Colors.red,
closeIconColor: Colors.white,
),
);
setState(() {});
},
child: Container(
padding: EdgeInsets.fromLTRB(28, 7, 28, 7),
decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(7))),
child: Center(
child: Text("Ajouté",
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)),
),
))),
)
: SizedBox(
// Définir une largeur minimale pour le bouton "Ajouter"
width: 120, // Réglez cette valeur en fonction de vos besoins
child: Material(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: primaryColor,
child: InkWell(
splashColor: Colors.white.withOpacity(0.3),
onTap: () async {
await MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: primaryColor,
content: Text(
"Vous suivez à present ${widget.user.pseudo}",
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w400, fontSize: 20.h),
),
),
);
setState(() {});
},
child: Container(
padding: EdgeInsets.fromLTRB(25, 7, 25, 7),
decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(7))),
child: Center(
child: Text("Ajouter",
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)),
),
)))),
),
MyApp.userViewModel.userCurrent.id != widget.user.id
? Align(
alignment: Alignment.topCenter,
child: isClicked
? SizedBox(
// Définir une largeur minimale pour le bouton "Ajouter"
width: 120, // Réglez cette valeur en fonction de vos besoins
child: Material(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: selectedButton,
child: InkWell(
splashColor: Colors.white.withOpacity(0.3),
onTap: () async {
await MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Vous ne suivez plus ${widget.user.pseudo}",
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w400, fontSize: 20.h),
),
backgroundColor: Colors.red,
closeIconColor: Colors.white,
),
);
setState(() {});
},
child: Container(
padding: EdgeInsets.fromLTRB(28, 7, 28, 7),
decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(7))),
child: Center(
child: Text("Ajouté",
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)),
),
))),
)
: SizedBox(
// Définir une largeur minimale pour le bouton "Ajouter"
width: 120, // Réglez cette valeur en fonction de vos besoins
child: Material(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: primaryColor,
child: InkWell(
splashColor: Colors.white.withOpacity(0.3),
onTap: () async {
await MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: primaryColor,
content: Text(
"Vous suivez à present ${widget.user.pseudo}",
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w400, fontSize: 20.h),
),
),
);
setState(() {});
},
child: Container(
padding: EdgeInsets.fromLTRB(25, 7, 25, 7),
decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(7))),
child: Center(
child: Text("Ajouter",
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13)),
),
)))),
)
: Container(),
SizedBox(
height: 40,
),
RecapComponent()
RecapComponent(user: widget.user)
],
),
),

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

Loading…
Cancel
Save