fix notif with text but still error gestion mutliple notif

pull/31/head
Lucas Delanier 2 years ago
parent 4609237105
commit 5668d2ff36

@ -23,6 +23,7 @@ class TopNavBarComponent extends StatefulWidget {
class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProviderStateMixin { class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProviderStateMixin {
bool choice = true; bool choice = true;
late AnimationController _controller; late AnimationController _controller;
bool isDismissed = true;
final DateTime midnight = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1); final DateTime midnight = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1);
@ -31,11 +32,6 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
MyApp.postViewModel.getBestPosts(); MyApp.postViewModel.getBestPosts();
} }
void checkAvailable() async {
var res = await MyApp.postViewModel.getAvailable();
showCapsuleDot(res);
}
@override @override
void initState() { void initState() {
_controller = AnimationController( _controller = AnimationController(
@ -112,9 +108,21 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
).show(context); ).show(context);
} }
void checkAvailable() async {
print("test");
var res = await MyApp.postViewModel.getAvailable();
print(res);
ModalRoute<dynamic>? route = ModalRoute.of(context);
if (route != null) {
if (route.settings.name != '/flushbarRoute') {
print("yes");
showCapsuleDot(res);
}
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
checkAvailable();
return Padding( return Padding(
padding: const EdgeInsets.only(top: defaultPadding), padding: const EdgeInsets.only(top: defaultPadding),
child: Container( child: Container(
@ -129,8 +137,11 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
flex: 1, flex: 1,
child: GestureDetector( child: GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () async {
Navigator.of(context).push(routeAddFriend()); bool returnFromOtherPage = await Navigator.of(context).push(routeAddFriend());
if (returnFromOtherPage == true) {
checkAvailable();
}
}, },
child: const Icon( child: const Icon(
Icons.person_add_alt_1_rounded, Icons.person_add_alt_1_rounded,
@ -225,8 +236,11 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
Flexible( Flexible(
flex: 1, flex: 1,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () async {
Navigator.of(context).push(routeProfile()); bool returnFromOtherPage = await Navigator.of(context).push(routeProfile());
if (returnFromOtherPage == true) {
checkAvailable();
}
}, },
child: ClipOval( child: ClipOval(
child: SizedBox.fromSize( child: SizedBox.fromSize(

@ -169,7 +169,7 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
GestureDetector( GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(context, true);
}, },
child: Transform( child: Transform(
alignment: Alignment.center, alignment: Alignment.center,

@ -32,7 +32,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
GestureDetector( GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(context, true);
}, },
child: Container( child: Container(
padding: EdgeInsets.symmetric(horizontal: 10), padding: EdgeInsets.symmetric(horizontal: 10),

@ -2,14 +2,14 @@ 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';
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,
@ -45,14 +45,11 @@ class PostService {
getPostsById(String id) {} getPostsById(String id) {}
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,16 +64,16 @@ class PostService {
Future<bool> getAvailable(String idUser) async { Future<bool> getAvailable(String idUser) async {
DateTime today = DateTime.now(); DateTime today = DateTime.now();
today = DateTime(today.year, today.month, today.day);
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) // Utiliser any() pour vérifier s'il y a au moins un document avec la date d'aujourd'hui
.where("date", isGreaterThanOrEqualTo: today) bool isTodayAvailable = response.docs.any((doc) {
.where("date", isLessThan: today.add(Duration(days: 1))) DateTime date = doc["date"].toDate(); // Assuming the field name is "date"
.get(); return date.day == today.day && date.month == today.month && date.year == today.year;
});
return response.docs.isNotEmpty; return !isTodayAvailable;
} }
} }

Loading…
Cancel
Save