|
|
|
@ -67,15 +67,45 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final ScrollController _scrollController = ScrollController();
|
|
|
|
|
String formatPostDate(DateTime postDate) {
|
|
|
|
|
DateTime now = DateTime.now();
|
|
|
|
|
DateTime yesterday = DateTime(now.year, now.month, now.day - 1);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
var mins = "0";
|
|
|
|
|
if (widget.post.date.minute < 10) {
|
|
|
|
|
mins = "0${widget.post.date.minute}";
|
|
|
|
|
if (postDate.year == now.year && postDate.month == now.month && postDate.day == now.day) {
|
|
|
|
|
// Aujourd'hui
|
|
|
|
|
return "Aujourd'hui, ${postDate.hour}:${postDate.minute.toString().padLeft(2, '0')}";
|
|
|
|
|
} else if (postDate.year == yesterday.year && postDate.month == yesterday.month && postDate.day == yesterday.day) {
|
|
|
|
|
// Hier
|
|
|
|
|
return 'hier, ${postDate.hour}:${postDate.minute.toString().padLeft(2, '0')}';
|
|
|
|
|
} else {
|
|
|
|
|
mins = widget.post.date.minute.toString();
|
|
|
|
|
// Autre date
|
|
|
|
|
return '${postDate.day} ${_getMonthAbbreviation(postDate.month)} ${postDate.hour}:${postDate.minute.toString().padLeft(2, '0')}';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String _getMonthAbbreviation(int month) {
|
|
|
|
|
const List<String> monthsAbbreviation = [
|
|
|
|
|
'janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return monthsAbbreviation[month - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exemple d'utilisation :
|
|
|
|
|
void main() {
|
|
|
|
|
DateTime postDate = DateTime(2023, 11, 17, 17, 55); // Remplacez par votre date
|
|
|
|
|
|
|
|
|
|
String formattedDate = formatPostDate(postDate);
|
|
|
|
|
print(formattedDate); // Affichera "17 nov. 17:55" ou "hier, 17:55" selon la date
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
_scrollController.addListener(() {
|
|
|
|
|
if (_scrollController.position.pixels < 0) _scrollController.jumpTo(0);
|
|
|
|
|
});
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
onTap: () {
|
|
|
|
|
FocusScopeNode currentFocus = FocusScope.of(context);
|
|
|
|
@ -86,6 +116,7 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
height: 760.h,
|
|
|
|
|
color: bgAppBar,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
@ -184,25 +215,8 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
|
|
|
child: choice
|
|
|
|
|
? DateTime(today.year, today.month, today.day)
|
|
|
|
|
.isAtSameMomentAs(
|
|
|
|
|
DateTime(
|
|
|
|
|
widget.post.date.year,
|
|
|
|
|
widget.post.date.month,
|
|
|
|
|
widget.post.date.day,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
? Text(
|
|
|
|
|
"Aujourd'hui, ${widget.post.date.hour}:$mins",
|
|
|
|
|
style: GoogleFonts.plusJakartaSans(
|
|
|
|
|
height: 1,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.w900,
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Text(
|
|
|
|
|
"hier, ${widget.post.date.hour}:$mins",
|
|
|
|
|
formatPostDate(widget.post.date),
|
|
|
|
|
style: GoogleFonts.plusJakartaSans(
|
|
|
|
|
height: 1,
|
|
|
|
|
color: Colors.white,
|
|
|
|
@ -263,11 +277,12 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
widget.post.description != null
|
|
|
|
|
? Align(
|
|
|
|
|
widget.post.description != null ? Align(
|
|
|
|
|
alignment: Alignment.bottomLeft,
|
|
|
|
|
child: Padding(
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(50, 35, 50, 35),
|
|
|
|
|
color: bgModal,
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: Text(
|
|
|
|
|
widget.post.description!,
|
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
@ -281,7 +296,7 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Container(
|
|
|
|
|
height: 30,
|
|
|
|
|
height: 0,
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
@ -630,12 +645,12 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
|
|
|
|
|
_textController.clear();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
icon: Icon(
|
|
|
|
|
icon: const Icon(
|
|
|
|
|
Icons.send,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
size: 20,
|
|
|
|
|
)),
|
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
|
focusedBorder: const OutlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(width: 1, color: grayText),
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(100)),
|
|
|
|
|
),
|
|
|
|
@ -643,7 +658,7 @@ class _DetailPostScreenState extends State<DetailPostScreen> {
|
|
|
|
|
fillColor: bgModal,
|
|
|
|
|
filled: true,
|
|
|
|
|
focusColor: Color.fromRGBO(255, 255, 255, 0.30),
|
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
enabledBorder: const OutlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(width: 1, color: grayText),
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(100)),
|
|
|
|
|
),
|
|
|
|
|