import 'package:eatvio_app/core/utils/date_time_utils.dart'; import 'package:eatvio_app/features/chat/models/chat_room_preview_model.dart'; import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; class ChatEntryWidget extends StatefulWidget { final ChatRoom chatRoom; ChatEntryWidget({ required this.chatRoom, super.key, }); @override State createState() => _ChatEntryWidgetState(); } class _ChatEntryWidgetState extends State { LastMessageClass? lastMessage; @override void initState() { super.initState(); if (widget.chatRoom.lastMessage is Map) { lastMessage = LastMessageClass.fromJson(widget.chatRoom.lastMessage); } } @override Widget build(BuildContext context) { return InkWell( borderRadius: BorderRadius.circular(16), onTap: () => GoRouter.of(context).pushNamed( 'chatScreen', extra: widget.chatRoom.id.toString(), ), child: Ink( padding: EdgeInsets.all(16), decoration: BoxDecoration( borderRadius: BorderRadius.circular(16), color: Color(0xFFF6FAFF), ), child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ CircleAvatar( radius: 24, backgroundImage: NetworkImage( widget.chatRoom.users.toChatUser.profilePhotoUrl, ), backgroundColor: Colors.white, ), const SizedBox(width: 12), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Text( widget.chatRoom.users.toChatUser.name.length <= 20 ? widget.chatRoom.users.toChatUser.name : widget.chatRoom.users.toChatUser.name.substring(0, 20) + '...', style: theme.textTheme.titleMedium, ), Spacer(), if (lastMessage != null) Padding( padding: EdgeInsets.only(left: 8), child: Text( lastMessage!.updatedAt.format('dd MMM', 'ru'), style: theme.textTheme.bodyMedium, ), ), ], ), SizedBox(height: 8), if (lastMessage != null) Text( lastMessage!.data.toString().trim(), maxLines: 2, overflow: TextOverflow.ellipsis, style: CustomTextStyles.bodyMediumBluegray800, ), ], ), ), ], ), ), ); } }