Skip to content

Commit 223c6cb

Browse files
sm-sayedignprice
authored andcommitted
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 0a0b940 commit 223c6cb

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/widgets/content.dart

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

18211821
/// A user status emoji to be displayed in different parts of the app.
18221822
///
1823+
/// Use [userId] to show status emoji for that user.
1824+
/// Use [emoji] to show the specific emoji passed.
1825+
///
1826+
/// Only one of [userId] or [emoji] should be passed.
1827+
///
18231828
/// Use [padding] to control the padding of status emoji from neighboring
18241829
/// widgets.
18251830
/// When there is no status emoji to be shown, the padding will be omitted too.
@@ -1829,13 +1834,16 @@ class _PresenceCircleState extends State<PresenceCircle> with PerAccountStoreAwa
18291834
class UserStatusEmoji extends StatelessWidget {
18301835
const UserStatusEmoji({
18311836
super.key,
1832-
required this.userId,
1837+
this.userId,
1838+
this.emoji,
18331839
required this.size,
18341840
this.padding = EdgeInsets.zero,
18351841
this.neverAnimate = true,
1836-
});
1842+
}) : assert((userId == null) != (emoji == null),
1843+
'Only one of the userId or emoji should be provided.');
18371844

1838-
final int userId;
1845+
final int? userId;
1846+
final StatusEmoji? emoji;
18391847
final double size;
18401848
final EdgeInsetsGeometry padding;
18411849
final bool neverAnimate;
@@ -1848,7 +1856,8 @@ class UserStatusEmoji extends StatelessWidget {
18481856
/// Use [position] to tell the emoji span where it is located relative to
18491857
/// another span, so that it can adjust the necessary padding from it.
18501858
static InlineSpan asWidgetSpan({
1851-
required int userId,
1859+
int? userId,
1860+
StatusEmoji? emoji,
18521861
required double fontSize,
18531862
required TextScaler textScaler,
18541863
StatusEmojiPosition position = StatusEmojiPosition.after,
@@ -1861,23 +1870,23 @@ class UserStatusEmoji extends StatelessWidget {
18611870
final size = textScaler.scale(fontSize);
18621871
return WidgetSpan(
18631872
alignment: PlaceholderAlignment.middle,
1864-
child: UserStatusEmoji(userId: userId, size: size,
1873+
child: UserStatusEmoji(userId: userId, emoji: emoji, size: size,
18651874
padding: EdgeInsetsDirectional.only(start: paddingStart, end: paddingEnd),
18661875
neverAnimate: neverAnimate));
18671876
}
18681877

18691878
@override
18701879
Widget build(BuildContext context) {
18711880
final store = PerAccountStoreWidget.of(context);
1872-
final emoji = store.getUserStatus(userId).emoji;
1881+
final effectiveEmoji = emoji ?? store.getUserStatus(userId!).emoji;
18731882

18741883
final placeholder = SizedBox.shrink();
1875-
if (emoji == null) return placeholder;
1884+
if (effectiveEmoji == null) return placeholder;
18761885

18771886
final emojiDisplay = store.emojiDisplayFor(
1878-
emojiType: emoji.reactionType,
1879-
emojiCode: emoji.emojiCode,
1880-
emojiName: emoji.emojiName)
1887+
emojiType: effectiveEmoji.reactionType,
1888+
emojiCode: effectiveEmoji.emojiCode,
1889+
emojiName: effectiveEmoji.emojiName)
18811890
// Web doesn't seem to respect the emojiset user settings for user status.
18821891
// .resolve(store.userSettings)
18831892
;

0 commit comments

Comments
 (0)