Skip to content

Add automatic text scaling support to IconCraft#5

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/support-text-scale-automation
Draft

Add automatic text scaling support to IconCraft#5
Copilot wants to merge 3 commits intomainfrom
copilot/support-text-scale-automation

Conversation

Copy link

Copilot AI commented Jan 31, 2026

IconCraft currently requires manual textScaleFactor multiplication on icon sizes, breaking Flutter's accessibility pattern. This adds automatic text scaling when IconThemeData(applyTextScaling: true) is set.

Changes

  • lib/src/icon_craft.dart: Apply MediaQuery.textScalerOf(context).scale() when iconTheme.applyTextScaling is true. Both primary and secondary icons scale proportionally.
  • test/icon_craft_test.dart: Add tests for scaling behavior (1.5x, 2.0x, 1.0x), proportional secondary icon scaling, and backward compatibility.
  • CHANGELOG.md: Document feature in v0.2.0.

Usage

// Before
final textScaleFactor = MediaQuery.textScalerOf(context).scale(1.0);
IconCraft(
  Icon(Icons.email, size: 24 * textScaleFactor),
  Icon(Icons.check, size: 24 * textScaleFactor),
)

// After
ThemeData(iconTheme: IconThemeData(applyTextScaling: true))
IconCraft(
  Icon(Icons.email, size: 24),  // Scales automatically
  Icon(Icons.check),
)

Backward compatible: applyTextScaling defaults to false/null, preserving existing behavior.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 8.8.8.8
    • Triggering command: REDACTED, pid is -1 (packet block)
  • dl-ssl.google.com
    • Triggering command: /usr/bin/wget wget -qO- REDACTED (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)
  • google.com
    • Triggering command: /usr/bin/ping ping -c 1 google.com (dns block)
  • https://storage.googleapis.com/flutter_infra_release/flutter/587c18f873b8ab57330422bce09047420d9c7f42/dart-sdk-linux-x64.zip
    • Triggering command: /usr/bin/curl curl --retry 3 --continue-at - --location --output /opt/flutter/bin/cache/dart-sdk-linux-x64.zip REDACTED (http block)
  • https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.16.8-stable.tar.xz
    • Triggering command: /usr/bin/wget wget -q REDACTED (http block)
    • Triggering command: /usr/bin/curl curl -L -o flutter_stable.tar.xz REDACTED --connect-timeout 30 --max-time 120 (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Support textScale automatically

Problem

Currently, when creating an IconCraft widget, developers have to manually calculate the size of the Icons to include the text scale factor from MediaQuery. This is not user-friendly and goes against Flutter's accessibility best practices.

Current Behavior

Users need to manually multiply icon sizes by textScaleFactor:

final double textScaleFactor = MediaQuery.textScalerOf(context).scale(1.0);

IconCraft(
  Icon(
    Icons.calendar_today_rounded,
    color: iconColorAlternative,
    size: 24 * textScaleFactor, // manual multiplication required
  ),
  Icon(
    Icons.switch_access_shortcut,
    color: iconColorAlternative,
    size: 24 * textScaleFactor, // manual multiplication required
  ),
);

Expected Behavior

IconCraft should automatically respect textScaleFactor from MediaQuery when IconTheme has applyTextScaling: true, just like Flutter's native Icon widget does:

ThemeData(
  iconTheme: const IconThemeData(applyTextScaling: true),
);

MediaQuery(
  data: MediaQuery.of(context).copyWith(
    textScaler: TextScaler.linear(textScaleFactor),
  ),
  child: IconCraft(
    Icon(
      Icons.calendar_today_rounded,
      color: iconColorAlternative,
      size: 24, // no manual multiplication needed
    ),
    Icon(
      Icons.switch_access_shortcut,
      color: iconColorAlternative,
      size: 24, // no manual multiplication needed
    ),
  ),
);

Implementation Requirements

1. Modify lib/src/icon_craft.dart

  • Add support for applyTextScaling from IconThemeData
  • Automatically apply textScaleFactor from MediaQuery.textScalerOf(context) to icon sizes when applyTextScaling is enabled
  • Ensure both primary and secondary icons respect the text scaling
  • Maintain backward compatibility (if applyTextScaling is false or not set, behavior should remain unchanged)

2. Add Tests in test/icon_craft_test.dart

Add the following test cases:

  • Test that icons apply text scaling when IconThemeData(applyTextScaling: true) is set
  • Test that icon sizes scale correctly with different TextScaler values (e.g., 1.5x, 2.0x)
  • Test that both primary and secondary icons scale proportionally
  • Test that without applyTextScaling: true, icons maintain their original behavior (no automatic scaling)
  • Test edge cases (textScaleFactor = 1.0 should not change anything)

3. Update CHANGELOG.md

Add an entry for this feature under a new version section following the existing format.

Technical Details

Reference the current implementation in lib/src/icon_craft.dart:

  • Line 58-60: Where iconSize and secondaryIconSize are currently calculated
  • The implementation should check iconTheme.applyTextScaling (similar to how Flutter's Icon widget works)
  • Use MediaQuery.textScalerOf(context) to get the current text scale factor
  • Apply the scale factor to both iconSize and secondaryIconSize

Success Criteria

  • IconCraft automatically applies text scaling when IconThemeData(applyTextScaling: true) is configured
  • Both primary and secondary icons scale proportionally
  • Backward compatibility is maintained (existing code without applyTextScaling continues to work)
  • Comprehensive tests validate the new behavior
  • CHANGELOG is updated with the new feature

Related Issue

Closes #4

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 31, 2026 22:32
Co-authored-by: vicenterusso <80538+vicenterusso@users.noreply.github.com>
Co-authored-by: vicenterusso <80538+vicenterusso@users.noreply.github.com>
Copilot AI changed the title [WIP] Support automatic textScale in IconCraft widget Add automatic text scaling support to IconCraft Jan 31, 2026
Copilot AI requested a review from vicenterusso January 31, 2026 22:34
@JamesMcIntosh
Copy link

@vicenterusso Could you look at this one too please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support text scaling automatically

3 participants