Skip to content

Commit 6c1b1ed

Browse files
Wahid NasriWahid Nasri
Wahid Nasri
authored and
Wahid Nasri
committed
add border color in recent chat page preparing for presence
1 parent 459afe6 commit 6c1b1ed

File tree

3 files changed

+57
-27
lines changed

3 files changed

+57
-27
lines changed

lib/ui/items/contact_or_group_item.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class ContactOrGroupItem extends StatelessWidget {
88
final Function()? onTap;
99
final Widget? subtitle;
1010
final Widget? trailing;
11-
const ContactOrGroupItem({Key? key, required this.chat, this.onTap, this.subtitle, this.trailing})
11+
final int? avatarBorderWidth;
12+
final Color? avatarBorderColor;
13+
const ContactOrGroupItem({Key? key, required this.chat, this.onTap, this.subtitle, this.trailing, this.avatarBorderWidth, this.avatarBorderColor})
1214
: super(key: key);
1315

1416
@override
@@ -28,7 +30,7 @@ class ContactOrGroupItem extends StatelessWidget {
2830
],
2931
),
3032
subtitle: subtitle ?? Text("Room: " + chat.roomId),
31-
leading: Hero(tag: "avatar_" + chat.id, child: ContactAvatar(chat: chat)),
33+
leading: Hero(tag: "avatar_" + chat.id, child: ContactAvatar(chat: chat, borderColor: avatarBorderColor, borderWidth: avatarBorderWidth)),
3234
trailing: trailing,
3335
),
3436
);

lib/ui/screens/main/chats_page.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class ChatsPage extends StatelessWidget {
2929
chat: chats[position].toContactChat(),
3030
subtitle: _subtitle(chats[position]),
3131
trailing: Text(DateFormat('HH:mm').format(dt)),
32+
avatarBorderWidth: chats[position].is_group ? 0 : 2,
33+
avatarBorderColor: chats[position].is_group ? null : Colors.grey,//fixme: use color for presence
3234
onTap: () {
3335
_openRoom(context, chats[position].toContactChat());
3436
});

lib/ui/views/contact_avatar.dart

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,66 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_mqtt/abstraction/models/ContactChat.dart';
3+
import 'package:flutter_mqtt/ui/widgets/avatar_cancellable.dart';
34

45
class ContactAvatar extends StatelessWidget {
56
final ContactChat chat;
67
final double? radius;
7-
const ContactAvatar({Key? key, required this.chat, this.radius})
8+
final int? borderWidth;
9+
final Color? borderColor;
10+
const ContactAvatar(
11+
{Key? key,
12+
required this.chat,
13+
this.radius,
14+
this.borderWidth,
15+
this.borderColor})
816
: super(key: key);
917

1018
@override
1119
Widget build(BuildContext context) {
1220
if (chat.isGroup ?? false) {
13-
return chat.avatar != null
14-
? CircleAvatar(
15-
foregroundImage: NetworkImage(chat.avatar!),
16-
radius: radius ?? 20,
17-
)
18-
: CircleAvatar(
19-
child: Icon(
20-
Icons.group,
21-
size: radius ?? 25,
22-
),
23-
radius: radius ?? 20,
24-
);
21+
return _buildForGroup();
2522
} else {
26-
return chat.avatar != null
27-
? CircleAvatar(
28-
foregroundImage: NetworkImage(
29-
chat.avatar!,
30-
),
31-
radius: radius ?? 20)
32-
: CircleAvatar(
33-
child: Icon(
34-
Icons.person,
35-
size: radius ?? 25,
36-
),
37-
radius: radius ?? 20);
23+
return _buildForContact();
3824
}
3925
}
26+
27+
Widget _buildForGroup() {
28+
double theRadiusForImage = radius ?? 20;
29+
double iconSize = radius ?? 25;
30+
return chat.avatar != null
31+
? CircleAvatar(
32+
foregroundImage: NetworkImage(chat.avatar!),
33+
radius: theRadiusForImage,
34+
)
35+
: CircleAvatar(
36+
child: Icon(
37+
Icons.group,
38+
size: iconSize,
39+
),
40+
radius: theRadiusForImage,
41+
);
42+
}
43+
44+
Widget _buildForContact() {
45+
double theRadiusForImage = radius ?? 20;
46+
double iconSize = radius ?? 25;
47+
int theBorderWidth = borderWidth ?? 0;
48+
49+
return chat.avatar != null
50+
? CircleAvatar(
51+
radius: theRadiusForImage + theBorderWidth,
52+
backgroundColor: borderColor ?? Colors.grey,
53+
child: CircleAvatar(
54+
foregroundImage: NetworkImage(
55+
chat.avatar!,
56+
),
57+
radius: theRadiusForImage),
58+
)
59+
: CircleAvatar(
60+
child: Icon(
61+
Icons.person,
62+
size: iconSize,
63+
),
64+
radius: theRadiusForImage);
65+
}
4066
}

0 commit comments

Comments
 (0)