2019-04-23 15:29:58 +00:00
|
|
|
import 'package:comunic/helpers/conversations_helper.dart';
|
|
|
|
import 'package:comunic/lists/users_list.dart';
|
2019-04-23 12:35:41 +00:00
|
|
|
import 'package:comunic/models/conversation.dart';
|
2019-04-23 14:38:41 +00:00
|
|
|
import 'package:comunic/utils/date_utils.dart';
|
2019-04-23 12:35:41 +00:00
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Single conversation tile
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
|
|
|
class ConversationTile extends StatelessWidget {
|
|
|
|
final Conversation conversation;
|
2019-04-23 15:29:58 +00:00
|
|
|
final UsersList usersList;
|
2019-04-23 12:35:41 +00:00
|
|
|
|
2019-04-23 15:29:58 +00:00
|
|
|
const ConversationTile(
|
|
|
|
{Key key, @required this.conversation, @required this.usersList})
|
|
|
|
: assert(conversation != null),
|
|
|
|
assert(usersList != null),
|
|
|
|
super(key: key);
|
2019-04-23 12:35:41 +00:00
|
|
|
|
|
|
|
_buildSubInformation(IconData icon, String content) {
|
|
|
|
return Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(
|
|
|
|
icon,
|
|
|
|
size: 15.0,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
|
|
|
Text(" " + content),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListTile(
|
2019-04-23 16:23:34 +00:00
|
|
|
// Conversation name
|
|
|
|
title: Text(
|
|
|
|
ConversationsHelper.getConversationName(
|
|
|
|
conversation,
|
|
|
|
usersList,
|
|
|
|
),
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: conversation.sawLastMessage ? null : FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
// Leading icon
|
2019-04-23 12:35:41 +00:00
|
|
|
leading: Icon(
|
|
|
|
conversation.sawLastMessage ? Icons.check_circle : Icons.lens,
|
|
|
|
color: conversation.sawLastMessage ? null : Colors.blue,
|
|
|
|
),
|
2019-04-23 16:23:34 +00:00
|
|
|
|
|
|
|
// Conversation information
|
2019-04-23 12:35:41 +00:00
|
|
|
isThreeLine: true,
|
|
|
|
subtitle: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
2019-04-23 14:38:41 +00:00
|
|
|
_buildSubInformation(
|
|
|
|
Icons.access_time, diffTimeFromNowToStr(conversation.lastActive)),
|
2019-04-23 12:35:41 +00:00
|
|
|
_buildSubInformation(
|
|
|
|
Icons.group,
|
|
|
|
conversation.members.length == 1
|
|
|
|
? tr("1 member")
|
|
|
|
: tr(
|
|
|
|
"%num% members",
|
|
|
|
args: {
|
|
|
|
"num": conversation.members.length.toString(),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|