Skip to content

Conversation

@rxlabz
Copy link
Contributor

@rxlabz rxlabz commented Sep 20, 2019

Simple fix for the toggleButtonsTheme type of the ThemeData.copyWith method.

Related Issues

see #40992

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Sep 20, 2019
@fluttergithubbot
Copy link
Contributor

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.

@shihaohong
Copy link
Contributor

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?

@rxlabz
Copy link
Contributor Author

rxlabz commented Sep 24, 2019

My pleasure !
Here a first test, a ThemeData.copyWith test passing all arguments and verifying if all values are correctly set in the returned instance : 6553ce4
Should I add more tests ?

@rxlabz rxlabz changed the title Fix the copyWith toggleButtonsTheme argument type Fix the ThemeData.copyWith toggleButtonsTheme argument type Sep 24, 2019
expect(theme.applyElevationOverlayColor, isTrue);
});

testWidgets('ThemeData.copyWith return appropriate value', (WidgetTester tester) async {
Copy link
Contributor

@shihaohong shihaohong Sep 25, 2019

Choose a reason for hiding this comment

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

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)

Copy link
Contributor Author

@rxlabz rxlabz Sep 25, 2019

Choose a reason for hiding this comment

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

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 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

@HansMuller HansMuller Sep 25, 2019

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 ,
Copy link
Contributor

Choose a reason for hiding this comment

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

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));
Copy link
Contributor

@shihaohong shihaohong Sep 26, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right ! Now it's 2 distincts ThemeData.raw instances.

rxlabz and others added 3 commits September 26, 2019 21:17
Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

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.

rxlabz and others added 2 commits September 27, 2019 08:51
Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
@shihaohong
Copy link
Contributor

Seems to still be failing the analyze test because of whitespace at the end of some of your lines. Make sure that this passes [and all failing tests after, if any]

▌06:59:13▐ ELAPSED TIME: 0.019s for grep --line-number --extended-regexp [[:blank:]]$ packages/flutter/lib/src/material/theme_data.dart packages/flutter/test/material/theme_data_test.dart in .
Whitespace detected at the end of source code lines.

@rxlabz
Copy link
Contributor Author

rxlabz commented Sep 27, 2019

I fixed the analyzer step. Now the 2 failings steps seems not related to my MR.

Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

LGTM

rxlabz and others added 2 commits September 29, 2019 17:20
Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
@rxlabz
Copy link
Contributor Author

rxlabz commented Sep 30, 2019

All green !

@shihaohong shihaohong merged commit d122f09 into flutter:master Sep 30, 2019
@shihaohong
Copy link
Contributor

@rxlabz Thank you for the contribution! I just merged :)

@rxlabz rxlabz deleted the fix-copywith-togglebuttonstheme branch September 30, 2019 16:37
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
…40994)

* set the copyWith toggleButtonsTheme argument type to ToggleButtonsThemeData

* add a ThemeData.copyWith test
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants