fluffychat/lib/components/list_items/chat_list_item.dart

119 lines
3.8 KiB
Dart
Raw Normal View History

2020-01-01 19:10:13 +01:00
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/message_content.dart';
2020-01-03 09:20:30 +01:00
import 'package:fluffychat/utils/chat_time.dart';
2020-01-01 19:10:13 +01:00
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart';
import '../avatar.dart';
class ChatListItem extends StatelessWidget {
final Room room;
final bool activeChat;
const ChatListItem(this.room, {this.activeChat = false});
@override
Widget build(BuildContext context) {
return Material(
color: activeChat ? Color(0xFFE8E8E8) : Colors.white,
child: ListTile(
leading: Avatar(room.avatar),
2020-01-03 09:09:14 +01:00
title: Row(
children: <Widget>[
Expanded(
child: Text(
room.displayname,
maxLines: 1,
2020-01-03 12:04:24 +01:00
overflow: TextOverflow.ellipsis,
),
),
SizedBox(width: 16),
Text(
ChatTime(room.timeCreated).toEventTimeString(),
style: TextStyle(
color: Color(0xFF555555),
2020-01-03 14:44:39 +01:00
fontSize: 13,
2020-01-03 09:09:14 +01:00
),
),
],
),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(child: MessageContent(room.lastEvent, textOnly: true)),
SizedBox(width: 8),
room.pushRuleState == PushRuleState.notify
? Container()
: Icon(
Icons.notifications_off,
color: Colors.grey,
2020-01-03 14:44:39 +01:00
size: 16,
2020-01-03 09:09:14 +01:00
),
room.notificationCount > 0
? Container(
2020-01-03 14:44:39 +01:00
padding: EdgeInsets.symmetric(horizontal: 5),
2020-01-03 09:09:14 +01:00
height: 20,
decoration: BoxDecoration(
color: room.highlightCount > 0
? Colors.red
2020-01-03 11:57:00 +01:00
: Theme.of(context).primaryColor,
2020-01-03 09:09:14 +01:00
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Text(
room.notificationCount.toString(),
style: TextStyle(color: Colors.white),
),
),
)
: Text(" "),
],
2020-01-02 23:38:46 +01:00
),
2020-01-01 19:10:13 +01:00
onTap: () {
2020-01-02 22:31:39 +01:00
if (activeChat) {
2020-01-01 19:10:13 +01:00
Navigator.pushReplacement(
context,
AppRoute.defaultRoute(context, Chat(room.id)),
);
2020-01-02 22:31:39 +01:00
} else {
2020-01-01 19:10:13 +01:00
Navigator.push(
context,
AppRoute.defaultRoute(context, Chat(room.id)),
);
2020-01-02 22:31:39 +01:00
}
2020-01-01 19:10:13 +01:00
},
onLongPress: () {},
2020-01-03 09:09:14 +01:00
/*trailing: Container(
2020-01-01 19:10:13 +01:00
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
2020-01-02 15:10:21 +01:00
Text(ChatTime(room.timeCreated).toEventTimeString()),
2020-01-01 19:10:13 +01:00
room.notificationCount > 0
? Container(
width: 20,
height: 20,
margin: EdgeInsets.only(top: 3),
decoration: BoxDecoration(
color: room.highlightCount > 0
? Colors.red
2020-01-03 11:57:00 +01:00
: Theme.of(context).primaryColor,
2020-01-01 19:10:13 +01:00
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Text(
room.notificationCount.toString(),
style: TextStyle(color: Colors.white),
),
),
)
: Text(" "),
],
),
2020-01-03 09:09:14 +01:00
),*/
2020-01-01 19:10:13 +01:00
),
);
}
}