Fix the ThemeData.copyWith toggleButtonsTheme argument type#40994
Fix the ThemeData.copyWith toggleButtonsTheme argument type#40994shihaohong merged 10 commits intoflutter:masterfrom rxlabz:fix-copywith-togglebuttonstheme
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. While there are exceptions to this rule, if this patch modifies code it is probably not an exception. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
Thanks for the contribution! We should really be writing a test or two to prevent #40992 from occurring again. Would you be willing to take that on? |
|
My pleasure ! |
| expect(theme.applyElevationOverlayColor, isTrue); | ||
| }); | ||
|
|
||
| testWidgets('ThemeData.copyWith return appropriate value', (WidgetTester tester) async { |
There was a problem hiding this comment.
What I find interesting is that this tests for whether or not all the values are properly overwritten, but not whether or not the argument type is correct. A side effect of this test is that the previous broken behavior will not be allowed. We should write a test that more directly verifies whether or not the argument types are correct/expected.
(This test is also absolutely needed by the way... we should probably create a test in a separate PR that ensures that ThemeData.copyWith properly overwrites individual properties while retaining the original values of the other properties)
There was a problem hiding this comment.
Thanks for the review.
I'm not sure about how to test the argument type correctness. Do you know where I can find an example of test of this kind please ?
I'm very surprised that analyzer can't detect the argument type error because of the fallback value.
// analyzer detects the type error
List<int> getList(String arg) => arg ;
// valid for the analyzer
List<int> getList(String arg) => arg ?? [0];Isn't it possible to change the analyzer configuration to avoid this behavior ?
There was a problem hiding this comment.
That is indeed strange, I hadn't considered that the analyzer should've caught this problem to begin with. This might actually be a Dart analyzer bug... could you file an issue?
We could just move forward with the test that you've already created, since that would catch the issue that we ran into, but also catch regressions in copyWith's behavior. @HansMuller, what do you think?
There was a problem hiding this comment.
The new test looks OK to me.
This sounds like either an analyzer issue or something subtle about Dart that we don't understand. In this case, neither return value is a List<int>:
List<int> getList(String arg) => arg ?? [0];I think the [0] is a List<dynamic>, <int>[0] would be a List<int>.
Filing a Dart analyzer issue sounds like a good idea.
There was a problem hiding this comment.
It's a known issue : dart-lang/sdk#25368, dart-lang/sdk#36964
For now disabling implicit-cast seems the only option but in near future implicit casts will be disabled to migrate to NNBD cf. dart-lang/sdk#36964 (comment)
| typography : darkTheme.typography , | ||
| cupertinoOverrideTheme : darkTheme.cupertinoOverrideTheme , | ||
| snackBarTheme : darkTheme.snackBarTheme , | ||
| bottomSheetTheme : darkTheme.bottomSheetTheme , |
There was a problem hiding this comment.
You're missing popupMenuTheme
| expect(themeDataCopy.cupertinoOverrideTheme, equals(darkTheme.cupertinoOverrideTheme)); | ||
| expect(themeDataCopy.snackBarTheme, equals(darkTheme.snackBarTheme)); | ||
| expect(themeDataCopy.bottomSheetTheme, equals(darkTheme.bottomSheetTheme)); | ||
| expect(themeDataCopy.popupMenuTheme, equals(darkTheme.popupMenuTheme)); |
There was a problem hiding this comment.
This unexpectedly passed. I think you might, unfortunately, have to use custom ThemeData values instead of light vs dark theme, since some of these properties are identical in both themes. This means that the existing test will not properly catch some regressions
There was a problem hiding this comment.
Right ! Now it's 2 distincts ThemeData.raw instances.
Co-Authored-By: Shi-Hao Hong <[email protected]>
Co-Authored-By: Shi-Hao Hong <[email protected]>
shihaohong
left a comment
There was a problem hiding this comment.
Thank you for thoroughly customizing each copy of ThemeData, this is a significant improvement to our ThemeData.copyWith testing!
Some stylistic nits for now... it seems like some trivial pre-submit tests are failing, so let's wait until those pass before I do a complete check of every property.
Co-Authored-By: Shi-Hao Hong <[email protected]>
Co-Authored-By: Shi-Hao Hong <[email protected]>
|
Seems to still be failing the |
|
I fixed the analyzer step. Now the 2 failings steps seems not related to my MR. |
Co-Authored-By: Shi-Hao Hong <[email protected]>
Co-Authored-By: Shi-Hao Hong <[email protected]>
|
All green ! |
|
@rxlabz Thank you for the contribution! I just merged :) |
…40994) * set the copyWith toggleButtonsTheme argument type to ToggleButtonsThemeData * add a ThemeData.copyWith test
Simple fix for the
toggleButtonsThemetype of theThemeData.copyWithmethod.Related Issues
see #40992