Skip to content

Commit 6e5d007

Browse files
Simplify if-else block into single return statement (#175574)
Follow up of flutter/flutter#175396 This PR applies the code change suggestion from gemini review ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Tong Mu <[email protected]>
1 parent a345163 commit 6e5d007

2 files changed

Lines changed: 21 additions & 42 deletions

File tree

packages/flutter/test/material/scrollbar_test.dart

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,9 @@ void main() {
934934
useMaterial3: false,
935935
scrollbarTheme: ScrollbarThemeData(
936936
thumbVisibility: WidgetStateProperty.all(true),
937-
trackVisibility: WidgetStateProperty.resolveWith((Set<WidgetState> states) {
938-
if (states.contains(WidgetState.hovered)) {
939-
return true;
940-
}
941-
return false;
942-
}),
937+
trackVisibility: WidgetStateProperty.resolveWith(
938+
(Set<WidgetState> states) => states.contains(WidgetState.hovered),
939+
),
943940
),
944941
),
945942
home: const SingleChildScrollView(child: SizedBox(width: 4000.0, height: 4000.0)),
@@ -1086,12 +1083,9 @@ void main() {
10861083
useMaterial3: false,
10871084
scrollbarTheme: ScrollbarThemeData(
10881085
thumbVisibility: WidgetStateProperty.all(true),
1089-
trackVisibility: WidgetStateProperty.resolveWith((Set<WidgetState> states) {
1090-
if (states.contains(WidgetState.hovered)) {
1091-
return true;
1092-
}
1093-
return false;
1094-
}),
1086+
trackVisibility: WidgetStateProperty.resolveWith(
1087+
(Set<WidgetState> states) => states.contains(WidgetState.hovered),
1088+
),
10951089
),
10961090
),
10971091
home: const SingleChildScrollView(child: SizedBox(width: 4000.0, height: 4000.0)),
@@ -1154,12 +1148,9 @@ void main() {
11541148
useMaterial3: false,
11551149
scrollbarTheme: ScrollbarThemeData(
11561150
thumbVisibility: WidgetStateProperty.all(true),
1157-
trackVisibility: WidgetStateProperty.resolveWith((Set<WidgetState> states) {
1158-
if (states.contains(WidgetState.hovered)) {
1159-
return true;
1160-
}
1161-
return false;
1162-
}),
1151+
trackVisibility: WidgetStateProperty.resolveWith(
1152+
(Set<WidgetState> states) => states.contains(WidgetState.hovered),
1153+
),
11631154
),
11641155
),
11651156
home: const SingleChildScrollView(child: SizedBox(width: 4000.0, height: 4000.0)),

packages/flutter/test/material/scrollbar_theme_test.dart

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ void main() {
3838
theme: ThemeData(
3939
useMaterial3: false,
4040
scrollbarTheme: ScrollbarThemeData(
41-
trackVisibility: WidgetStateProperty.resolveWith((Set<WidgetState> states) {
42-
if (states.contains(WidgetState.hovered)) {
43-
return true;
44-
}
45-
return false;
46-
}),
41+
trackVisibility: WidgetStateProperty.resolveWith(
42+
(Set<WidgetState> states) => states.contains(WidgetState.hovered),
43+
),
4744
),
4845
),
4946
home: ScrollConfiguration(
@@ -387,12 +384,9 @@ void main() {
387384
theme: ThemeData(
388385
colorScheme: const ColorScheme.light(),
389386
scrollbarTheme: ScrollbarThemeData(
390-
trackVisibility: WidgetStateProperty.resolveWith((Set<WidgetState> states) {
391-
if (states.contains(WidgetState.hovered)) {
392-
return true;
393-
}
394-
return false;
395-
}),
387+
trackVisibility: WidgetStateProperty.resolveWith(
388+
(Set<WidgetState> states) => states.contains(WidgetState.hovered),
389+
),
396390
),
397391
),
398392
home: ScrollConfiguration(
@@ -492,12 +486,9 @@ void main() {
492486
final ScrollController scrollController = ScrollController();
493487
final ThemeData theme = appTheme.copyWith(
494488
scrollbarTheme: ScrollbarThemeData(
495-
trackVisibility: WidgetStateProperty.resolveWith((Set<WidgetState> states) {
496-
if (states.contains(WidgetState.hovered)) {
497-
return true;
498-
}
499-
return false;
500-
}),
489+
trackVisibility: WidgetStateProperty.resolveWith(
490+
(Set<WidgetState> states) => states.contains(WidgetState.hovered),
491+
),
501492
),
502493
);
503494
return (
@@ -789,12 +780,9 @@ ScrollbarThemeData _scrollbarTheme({
789780
thickness: thickness ?? WidgetStateProperty.resolveWith(_getThickness),
790781
trackVisibility:
791782
trackVisibility ??
792-
WidgetStateProperty.resolveWith((Set<WidgetState> states) {
793-
if (states.contains(WidgetState.hovered)) {
794-
return true;
795-
}
796-
return false;
797-
}),
783+
WidgetStateProperty.resolveWith(
784+
(Set<WidgetState> states) => states.contains(WidgetState.hovered),
785+
),
798786
thumbVisibility: thumbVisibility,
799787
radius: radius,
800788
thumbColor: thumbColor ?? WidgetStateProperty.resolveWith(_getThumbColor),

0 commit comments

Comments
 (0)