Skip to content

chore: add tests for button inherited text style#1322

Draft
jacksonb-cs wants to merge 1 commit intobdlukaa:masterfrom
jacksonb-cs:add-button-text-style-tests
Draft

chore: add tests for button inherited text style#1322
jacksonb-cs wants to merge 1 commit intobdlukaa:masterfrom
jacksonb-cs:add-button-text-style-tests

Conversation

@jacksonb-cs
Copy link
Copy Markdown
Contributor

@jacksonb-cs jacksonb-cs commented Apr 14, 2026

Added (failing) tests covering buttons using inherited text style.

Tests covering expected fix for #1318. This PR does not fix the issue.

Also included a test to ensure the employed fix retains the current behavior of using the button's foreground color when no button text style is provided in the theme.

Pre-launch Checklist

  • I have updated CHANGELOG.md with my changes
  • I have run "dart format ." on the project
  • I have added/updated relevant documentation

Added (failing) tests covering buttons using inherited text style.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds new test cases to test/button_test.dart to verify that Button and FilledButton correctly apply default foreground colors and inherited text styles from the theme. It also introduces a _renderedTextStyle helper function to extract styles during testing. Feedback was provided regarding the fragility of the _renderedTextStyle helper, which may fail if a button contains multiple RichText descendants (e.g., an icon and text).

Comment on lines +4 to +10
TextStyle _renderedTextStyle(WidgetTester tester, Finder buttonFinder) {
final richTextFinder = find.descendant(
of: buttonFinder,
matching: find.byType(RichText),
);
return tester.widget<RichText>(richTextFinder).text.style!;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The _renderedTextStyle helper is fragile because it assumes exactly one RichText descendant exists within the button. In Flutter, widgets like Icon also use RichText internally. If a button were to include both an icon and text, this helper would fail with a 'too many elements' error. While it works for the current test cases, consider making the finder more specific to target the intended text label (e.g., by finding the Text widget first) or using .first if you only care about the primary style.

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.

1 participant