Skip to content

Commit 0104cd1

Browse files
committed
content: Add emoji property to UserStatusEmoji widget
This is useful when we want to show a status emoji that we already know about, instead of relying on `userId` to get the emoji for the user. For example in the next commits, in setting user status page, where a list of status suggestions are shown.
1 parent a90f83e commit 0104cd1

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

lib/widgets/content.dart

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,11 @@ class _PresenceCircleState extends State<PresenceCircle> with PerAccountStoreAwa
20122012

20132013
/// A user status emoji to be displayed in different parts of the app.
20142014
///
2015+
/// Use [userId] to show status emoji for that user.
2016+
/// Use [emoji] to show the specific emoji passed.
2017+
///
2018+
/// Only one of [userId] or [emoji] should be passed.
2019+
///
20152020
/// Use [padding] to control the padding of status emoji from neighboring
20162021
/// widgets.
20172022
/// When there is no status emoji to be shown, the padding will be omitted too.
@@ -2021,13 +2026,16 @@ class _PresenceCircleState extends State<PresenceCircle> with PerAccountStoreAwa
20212026
class UserStatusEmoji extends StatelessWidget {
20222027
const UserStatusEmoji({
20232028
super.key,
2024-
required this.userId,
2029+
this.userId,
2030+
this.emoji,
20252031
required this.size,
20262032
this.padding = EdgeInsets.zero,
20272033
this.neverAnimate = true,
2028-
});
2034+
}) : assert((userId == null) != (emoji == null),
2035+
'Only one of the userId or emoji should be provided.');
20292036

2030-
final int userId;
2037+
final int? userId;
2038+
final StatusEmoji? emoji;
20312039
final double size;
20322040
final EdgeInsetsGeometry padding;
20332041
final bool neverAnimate;
@@ -2040,7 +2048,8 @@ class UserStatusEmoji extends StatelessWidget {
20402048
/// Use [position] to tell the emoji span where it is located relative to
20412049
/// another span, so that it can adjust the necessary padding from it.
20422050
static InlineSpan asWidgetSpan({
2043-
required int userId,
2051+
int? userId,
2052+
StatusEmoji? emoji,
20442053
required double fontSize,
20452054
required TextScaler textScaler,
20462055
StatusEmojiPosition position = StatusEmojiPosition.after,
@@ -2053,23 +2062,25 @@ class UserStatusEmoji extends StatelessWidget {
20532062
final size = textScaler.scale(fontSize);
20542063
return WidgetSpan(
20552064
alignment: PlaceholderAlignment.middle,
2056-
child: UserStatusEmoji(userId: userId, size: size,
2065+
child: UserStatusEmoji(userId: userId, emoji: emoji, size: size,
20572066
padding: EdgeInsetsDirectional.only(start: paddingStart, end: paddingEnd),
20582067
neverAnimate: neverAnimate));
20592068
}
20602069

20612070
@override
20622071
Widget build(BuildContext context) {
20632072
final store = PerAccountStoreWidget.of(context);
2064-
final emoji = store.getUserStatus(userId).emoji;
2073+
final effectiveEmoji = userId != null
2074+
? store.getUserStatus(userId!).emoji
2075+
: emoji;
20652076

20662077
final placeholder = SizedBox.shrink();
2067-
if (emoji == null) return placeholder;
2078+
if (effectiveEmoji == null) return placeholder;
20682079

20692080
final emojiDisplay = store.emojiDisplayFor(
2070-
emojiType: emoji.reactionType,
2071-
emojiCode: emoji.emojiCode,
2072-
emojiName: emoji.emojiName)
2081+
emojiType: effectiveEmoji.reactionType,
2082+
emojiCode: effectiveEmoji.emojiCode,
2083+
emojiName: effectiveEmoji.emojiName)
20732084
// Web doesn't seem to respect the emojiset user settings for user status.
20742085
// .resolve(store.userSettings)
20752086
;

0 commit comments

Comments
 (0)