resolveFluentPersonaState function

FluentPersonaState resolveFluentPersonaState({
  1. String? name,
  2. Widget? primary,
  3. Widget? secondary,
  4. Widget? tertiary,
  5. Widget? quaternary,
  6. bool presenceOnly = false,
  7. FluentPersonaSize size = FluentPersonaSize.medium,
  8. FluentPersonaTextPosition textPosition = FluentPersonaTextPosition.after,
  9. FluentPersonaTextAlignment textAlignment = FluentPersonaTextAlignment.center,
  10. ImageProvider<Object>? image,
  11. String? initials,
  12. Widget? icon,
  13. FluentAvatarColor color = FluentAvatarColor.neutral,
  14. FluentAvatarShape shape = FluentAvatarShape.circular,
  15. FluentAvatarActive active = FluentAvatarActive.unset,
  16. FluentPresenceStatus? status,
  17. bool outOfOffice = false,
})

Builds the state a persona will be styled and rendered from.

The first of the three-function recomposition contract, and the one that composes: it builds a real FluentAvatar — or, with presenceOnly, a real FluentPresenceBadge — at the size size names, and hands it on as opaque content. Neither component's token table is duplicated anywhere in this file; the Size axis only chooses a FluentAvatarSize or a FluentPresenceBadgeSize.

primary defaults to name rendered as text, matching upstream. name is deliberately not also handed to the composed avatar as a semantic label: the primary line already carries it, and doing both makes a screen reader announce the person twice.

Implementation

FluentPersonaState resolveFluentPersonaState({
  String? name,
  Widget? primary,
  Widget? secondary,
  Widget? tertiary,
  Widget? quaternary,
  bool presenceOnly = false,
  FluentPersonaSize size = FluentPersonaSize.medium,
  FluentPersonaTextPosition textPosition = FluentPersonaTextPosition.after,
  FluentPersonaTextAlignment textAlignment = FluentPersonaTextAlignment.center,
  ImageProvider<Object>? image,
  String? initials,
  Widget? icon,
  FluentAvatarColor color = FluentAvatarColor.neutral,
  FluentAvatarShape shape = FluentAvatarShape.circular,
  FluentAvatarActive active = FluentAvatarActive.unset,
  FluentPresenceStatus? status,
  bool outOfOffice = false,
}) {
  final firstLine = primary ?? (name == null ? null : Text(name));
  final media = presenceOnly
      ? (status == null
            ? null
            : FluentPresenceBadge(
                status: status,
                outOfOffice: outOfOffice,
                size: size.presenceSize,
              ))
      : FluentAvatar(
          image: image,
          initials: initials,
          icon: icon,
          color: color,
          size: size.avatarSize,
          shape: shape,
          active: active,
          status: status,
          outOfOffice: outOfOffice,
        );

  return FluentPersonaState(
    size: size,
    presenceOnly: presenceOnly,
    textPosition: textPosition,
    textAlignment: textAlignment,
    alignMediaToPrimaryLine: presenceOnly,
    textLineCount: <Widget?>[
      firstLine,
      secondary,
      tertiary,
      quaternary,
    ].whereType<Widget>().length,
    media: media,
    primary: firstLine,
    secondary: secondary,
    tertiary: tertiary,
    quaternary: quaternary,
  );
}