Skip to content

FortalAvatar token arithmetic produces a negative icon size #86

Description

@leoafarias

Summary

FortalAvatar cannot safely render its default icon path because the recipe multiplies an unresolved Mix numeric token reference by 0.5.

Found while validating #80 at b16636b017f3c8832d8f27f316cc24c0ad92ce8a.

Evidence

fortal_avatar_styles.dart computes:

.icon(.size(_fortalAvatarDimension(size) * 0.5))

Every _fortalAvatarDimension branch returns a numeric Fortal token reference. Mix represents unresolved double references with registered negative sentinels; arithmetic produces a new unregistered value instead of a derived token.

A focused widget test captures -5e-7 for size 2 rather than the intended 16:

testWidgets('FortalAvatar resolves a valid icon size', (tester) async {
  double? resolvedSize;

  await tester.pumpRemixApp(
    FortalAvatar(
      size: FortalAvatarSize.size2,
      icon: Icons.person,
      iconBuilder: (context, spec, icon) {
        resolvedSize = spec.size;
        return const SizedBox.shrink();
      },
    ),
  );

  expect(resolvedSize, greaterThanOrEqualTo(0)); // actual: -5e-7
});

Without iconBuilder, Icon(size: -5e-7) reaches Flutter and throws because the generated BoxConstraints has a negative minimum width/height.

This reproduces with:

  • consumer Mix 2.2.0-beta.1;
  • the Remix workspace override at Mix revision 07dafe904e56a9b60a172f4ef1863cf45564603a.

The same PR head contains no other Fortal recipe expression that performs arithmetic on a numeric token reference.

Expected

All Fortal avatar sizes resolve a finite, nonnegative icon size that preserves FortalThemeConfig.scaling.

Suggested direction

  • Add explicit scaled avatar-icon-size tokens, or another token-preserving derived-value mechanism.
  • Avoid ordinary arithmetic on unresolved sentinel-backed token references.
  • Add default-icon widget coverage for every Fortal avatar size.
  • Add a source/parity check that rejects numeric token arithmetic in Fortal recipes.

Acceptance criteria

  • FortalAvatar(icon: ...) builds without an exception for sizes 1–9.
  • Resolved icon sizes equal half of the resolved avatar dimensions at default and non-default Fortal scaling.
  • The default icon path and iconBuilder receive the same valid geometry.
  • A regression test fails if a token reference is arithmetically transformed before resolution.

Ownership

This is a Remix/Fortal recipe defect, not a Mix interpolation defect. Mix correctly resolves registered token references; the recipe discards that identity before resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions