chore: add tests for button inherited text style#1322
chore: add tests for button inherited text style#1322jacksonb-cs wants to merge 1 commit intobdlukaa:masterfrom
Conversation
Added (failing) tests covering buttons using inherited text style.
There was a problem hiding this comment.
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).
| TextStyle _renderedTextStyle(WidgetTester tester, Finder buttonFinder) { | ||
| final richTextFinder = find.descendant( | ||
| of: buttonFinder, | ||
| matching: find.byType(RichText), | ||
| ); | ||
| return tester.widget<RichText>(richTextFinder).text.style!; | ||
| } |
There was a problem hiding this comment.
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.
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
CHANGELOG.mdwith my changes