Skip to content

Commit ab625e9

Browse files
committed
user: 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 a55e988 commit ab625e9

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/widgets/user.dart

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

290290
/// A user status emoji to be displayed in different parts of the app.
291291
///
292+
/// Use [userId] to show status emoji for that user.
293+
/// Use [emoji] to show the specific emoji passed.
294+
///
295+
/// Only one of [userId] or [emoji] should be passed.
296+
///
292297
/// Use [padding] to control the padding of status emoji from neighboring
293298
/// widgets.
294299
/// When there is no status emoji to be shown, the padding will be omitted too.
@@ -298,13 +303,16 @@ class _PresenceCircleState extends State<PresenceCircle> with PerAccountStoreAwa
298303
class UserStatusEmoji extends StatelessWidget {
299304
const UserStatusEmoji({
300305
super.key,
301-
required this.userId,
306+
this.userId,
307+
this.emoji,
302308
required this.size,
303309
this.padding = EdgeInsets.zero,
304310
this.neverAnimate = true,
305-
});
311+
}) : assert((userId == null) != (emoji == null),
312+
'Only one of the userId or emoji should be provided.');
306313

307-
final int userId;
314+
final int? userId;
315+
final StatusEmoji? emoji;
308316
final double size;
309317
final EdgeInsetsGeometry padding;
310318
final bool neverAnimate;
@@ -317,7 +325,8 @@ class UserStatusEmoji extends StatelessWidget {
317325
/// Use [position] to tell the emoji span where it is located relative to
318326
/// another span, so that it can adjust the necessary padding from it.
319327
static InlineSpan asWidgetSpan({
320-
required int userId,
328+
int? userId,
329+
StatusEmoji? emoji,
321330
required double fontSize,
322331
required TextScaler textScaler,
323332
StatusEmojiPosition position = StatusEmojiPosition.after,
@@ -330,23 +339,23 @@ class UserStatusEmoji extends StatelessWidget {
330339
final size = textScaler.scale(fontSize);
331340
return WidgetSpan(
332341
alignment: PlaceholderAlignment.middle,
333-
child: UserStatusEmoji(userId: userId, size: size,
342+
child: UserStatusEmoji(userId: userId, emoji: emoji, size: size,
334343
padding: EdgeInsetsDirectional.only(start: paddingStart, end: paddingEnd),
335344
neverAnimate: neverAnimate));
336345
}
337346

338347
@override
339348
Widget build(BuildContext context) {
340349
final store = PerAccountStoreWidget.of(context);
341-
final emoji = store.getUserStatus(userId).emoji;
350+
final effectiveEmoji = emoji ?? store.getUserStatus(userId!).emoji;
342351

343352
final placeholder = SizedBox.shrink();
344-
if (emoji == null) return placeholder;
353+
if (effectiveEmoji == null) return placeholder;
345354

346355
final emojiDisplay = store.emojiDisplayFor(
347-
emojiType: emoji.reactionType,
348-
emojiCode: emoji.emojiCode,
349-
emojiName: emoji.emojiName)
356+
emojiType: effectiveEmoji.reactionType,
357+
emojiCode: effectiveEmoji.emojiCode,
358+
emojiName: effectiveEmoji.emojiName)
350359
// Web doesn't seem to respect the emojiset user settings for user status.
351360
// .resolve(store.userSettings)
352361
;

0 commit comments

Comments
 (0)