roomListEntry method
Implementation
Widget roomListEntry(EnhancedRoomModel room, bool isCurrent) {
var timestampRoom = (room.roomModel.timestamp != null)
? room.roomModel.timestamp!
: DateTime.now();
var nameList = room.otherMembersRoomInfo.map((e) => e.name).toList();
var names = nameList.join(", ");
if (isCurrent) names = "*$names";
var nameWidget = room.hasUnread
? highLight1(
widget.app,
context,
names,
)
: text(
widget.app,
context,
names,
);
int amountOfAvatars = 0;
List<Widget> widgets = [];
if (room.otherMembersRoomInfo.length > 1) {
widgets.add(const Icon(Icons.group));
amountOfAvatars = 1;
} else {
for (int i = 0; i < room.otherMembersRoomInfo.length; i++) {
var avatar = room.otherMembersRoomInfo[i].avatar;
if (avatar != null) {
widgets.add(FadeInImage.memoryNetwork(
height: 10,
placeholder: kTransparentImage,
image: avatar,
));
amountOfAvatars++;
} else {
widgets.add(const Icon(Icons.person));
}
}
}
const double photoSize = 50;
const double spacing = 1;
Widget staggeredPhotos;
if (amountOfAvatars >= 1) {
var sqrtValue = sqrt(amountOfAvatars);
var maxCrossAxisExtend = (photoSize - (sqrtValue - 1)) / sqrtValue;
staggeredPhotos = GridView.extent(
maxCrossAxisExtent: maxCrossAxisExtend,
padding: const EdgeInsets.all(0),
mainAxisSpacing: spacing,
crossAxisSpacing: spacing,
physics: const ScrollPhysics(),
// to disable GridView's scrolling
shrinkWrap: true,
children: widgets);
} else {
staggeredPhotos = const Icon(Icons.error);
}
var theTime = formatHHMM(timestampRoom);
return ListTile(
onTap: () async {
selectRoom(context, room.roomModel);
},
trailing: text(widget.app, context, theTime),
leading: SizedBox(
height: photoSize,
width: photoSize,
child: staggeredPhotos,
),
title: nameWidget);
}