fluffychat/lib/components/list_items/chat_list_item.dart

73 lines
2.3 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-02 15:10:21 +01:00
import 'package:fluffychat/utils/ChatTime.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-02 23:38:46 +01:00
title: Text(
room.displayname,
maxLines: 1,
),
2020-01-01 19:10:13 +01:00
subtitle: MessageContent(room.lastEvent, textOnly: true),
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: () {},
trailing: Container(
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
: Color(0xFF5625BA),
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Text(
room.notificationCount.toString(),
style: TextStyle(color: Colors.white),
),
),
)
: Text(" "),
],
),
),
),
);
}
}