Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c3587c62
Unverified
Commit
c3587c62
authored
Feb 17, 2023
by
Taha Tesser
Committed by
GitHub
Feb 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `InheritedTheme` support to `ScrollbarTheme` (#120970)
parent
51712b90
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
192 additions
and
1 deletion
+192
-1
scrollbar_theme.dart
packages/flutter/lib/src/material/scrollbar_theme.dart
+6
-1
menu_anchor_test.dart
packages/flutter/test/material/menu_anchor_test.dart
+97
-0
popup_menu_test.dart
packages/flutter/test/material/popup_menu_test.dart
+89
-0
No files found.
packages/flutter/lib/src/material/scrollbar_theme.dart
View file @
c3587c62
...
...
@@ -299,7 +299,7 @@ bool? _lerpBool(bool? a, bool? b, double t) => t < 0.5 ? a : b;
///
/// * [ScrollbarThemeData], which describes the configuration of a
/// scrollbar theme.
class
ScrollbarTheme
extends
Inherited
Widget
{
class
ScrollbarTheme
extends
Inherited
Theme
{
/// Constructs a scrollbar theme that configures all descendant [Scrollbar]
/// widgets.
const
ScrollbarTheme
({
...
...
@@ -324,6 +324,11 @@ class ScrollbarTheme extends InheritedWidget {
return
scrollbarTheme
?.
data
??
Theme
.
of
(
context
).
scrollbarTheme
;
}
@override
Widget
wrap
(
BuildContext
context
,
Widget
child
)
{
return
ScrollbarTheme
(
data:
data
,
child:
child
);
}
@override
bool
updateShouldNotify
(
ScrollbarTheme
oldWidget
)
=>
data
!=
oldWidget
.
data
;
}
packages/flutter/test/material/menu_anchor_test.dart
View file @
c3587c62
...
...
@@ -9,6 +9,8 @@ import 'package:flutter/rendering.dart';
import
'package:flutter/services.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'../rendering/mock_canvas.dart'
;
void
main
(
)
{
late
MenuController
controller
;
String
?
focusedMenu
;
...
...
@@ -298,6 +300,101 @@ void main() {
expect
(
iconRichText
.
text
.
style
?.
color
,
themeData
.
colorScheme
.
onSurface
.
withOpacity
(
0.38
));
});
testWidgets
(
'Menu scrollbar inherits ScrollbarTheme'
,
(
WidgetTester
tester
)
async
{
const
ScrollbarThemeData
scrollbarTheme
=
ScrollbarThemeData
(
thumbColor:
MaterialStatePropertyAll
<
Color
?>(
Color
(
0xffff0000
)),
thumbVisibility:
MaterialStatePropertyAll
<
bool
?>(
true
),
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
scrollbarTheme:
scrollbarTheme
),
home:
Material
(
child:
MenuBar
(
children:
<
Widget
>[
SubmenuButton
(
menuChildren:
<
Widget
>[
MenuItemButton
(
style:
ButtonStyle
(
minimumSize:
MaterialStateProperty
.
all
<
Size
>(
const
Size
.
fromHeight
(
1000
),
),
),
onPressed:
()
{},
child:
const
Text
(
'Category'
,
),
),
],
child:
const
Text
(
'Main Menu'
,
),
),
],
),
),
),
);
await
tester
.
tap
(
find
.
text
(
'Main Menu'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
Scrollbar
),
findsOneWidget
);
// Test Scrollbar thumb color.
expect
(
find
.
byType
(
Scrollbar
),
paints
..
rrect
(
color:
const
Color
(
0xffff0000
)),
);
// Close the menu.
await
tester
.
tapAt
(
const
Offset
(
10.0
,
10.0
));
await
tester
.
pumpAndSettle
();
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
scrollbarTheme:
scrollbarTheme
),
home:
Material
(
child:
ScrollbarTheme
(
data:
scrollbarTheme
.
copyWith
(
thumbColor:
const
MaterialStatePropertyAll
<
Color
?>(
Color
(
0xff00ff00
)),
),
child:
MenuBar
(
children:
<
Widget
>[
SubmenuButton
(
menuChildren:
<
Widget
>[
MenuItemButton
(
style:
ButtonStyle
(
minimumSize:
MaterialStateProperty
.
all
<
Size
>(
const
Size
.
fromHeight
(
1000
),
),
),
onPressed:
()
{},
child:
const
Text
(
'Category'
,
),
),
],
child:
const
Text
(
'Main Menu'
,
),
),
],
),
),
),
),
);
await
tester
.
tap
(
find
.
text
(
'Main Menu'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
Scrollbar
),
findsOneWidget
);
// Scrollbar thumb color should be updated.
expect
(
find
.
byType
(
Scrollbar
),
paints
..
rrect
(
color:
const
Color
(
0xff00ff00
)),
);
},
variant:
TargetPlatformVariant
.
desktop
());
group
(
'Menu functions'
,
()
{
testWidgets
(
'basic menu structure'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
...
...
packages/flutter/test/material/popup_menu_test.dart
View file @
c3587c62
...
...
@@ -10,6 +10,7 @@ import 'package:flutter/material.dart';
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'../rendering/mock_canvas.dart'
;
import
'../widgets/semantics_tester.dart'
;
import
'feedback_tester.dart'
;
...
...
@@ -3098,6 +3099,94 @@ void main() {
expect
(
nodeA
().
hasFocus
,
true
);
expect
(
nodeB
().
hasFocus
,
false
);
});
testWidgets
(
'Popup menu scrollbar inherits ScrollbarTheme'
,
(
WidgetTester
tester
)
async
{
final
Key
popupButtonKey
=
UniqueKey
();
const
ScrollbarThemeData
scrollbarTheme
=
ScrollbarThemeData
(
thumbColor:
MaterialStatePropertyAll
<
Color
?>(
Color
(
0xffff0000
)),
thumbVisibility:
MaterialStatePropertyAll
<
bool
?>(
true
),
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
scrollbarTheme:
scrollbarTheme
,
useMaterial3:
true
,
),
home:
Material
(
child:
Column
(
children:
<
Widget
>[
PopupMenuButton
<
void
>(
key:
popupButtonKey
,
itemBuilder:
(
BuildContext
context
)
{
return
<
PopupMenuEntry
<
void
>>[
const
PopupMenuItem
<
void
>(
height:
1000
,
child:
Text
(
'Example'
),
),
];
},
),
],
),
),
)
);
await
tester
.
tap
(
find
.
byKey
(
popupButtonKey
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
Scrollbar
),
findsOneWidget
);
// Test Scrollbar thumb color.
expect
(
find
.
byType
(
Scrollbar
),
paints
..
rrect
(
color:
const
Color
(
0xffff0000
)),
);
// Close the menu.
await
tester
.
tapAt
(
const
Offset
(
20.0
,
20.0
));
await
tester
.
pumpAndSettle
();
// Test local ScrollbarTheme overrides global ScrollbarTheme.
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
scrollbarTheme:
scrollbarTheme
,
useMaterial3:
true
,
),
home:
Material
(
child:
Column
(
children:
<
Widget
>[
ScrollbarTheme
(
data:
scrollbarTheme
.
copyWith
(
thumbColor:
const
MaterialStatePropertyAll
<
Color
?>(
Color
(
0xff0000ff
)),
),
child:
PopupMenuButton
<
void
>(
key:
popupButtonKey
,
itemBuilder:
(
BuildContext
context
)
{
return
<
PopupMenuEntry
<
void
>>[
const
PopupMenuItem
<
void
>(
height:
1000
,
child:
Text
(
'Example'
),
),
];
},
),
),
],
),
),
)
);
await
tester
.
tap
(
find
.
byKey
(
popupButtonKey
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
Scrollbar
),
findsOneWidget
);
// Scrollbar thumb color should be updated.
expect
(
find
.
byType
(
Scrollbar
),
paints
..
rrect
(
color:
const
Color
(
0xff0000ff
)),
);
},
variant:
TargetPlatformVariant
.
desktop
());
}
class
TestApp
extends
StatelessWidget
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment