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
e84fa2ce
Unverified
Commit
e84fa2ce
authored
Jun 09, 2023
by
ZhulanovAA
Committed by
GitHub
Jun 09, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tooltips for `SegmentedButton` (#128501)
parent
a08a2110
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletion
+68
-1
segmented_button.dart
packages/flutter/lib/src/material/segmented_button.dart
+13
-1
segmented_button_test.dart
packages/flutter/test/material/segmented_button_test.dart
+55
-0
No files found.
packages/flutter/lib/src/material/segmented_button.dart
View file @
e84fa2ce
...
...
@@ -17,6 +17,7 @@ import 'segmented_button_theme.dart';
import
'text_button.dart'
;
import
'text_button_theme.dart'
;
import
'theme.dart'
;
import
'tooltip.dart'
;
/// Data describing a segment of a [SegmentedButton].
class
ButtonSegment
<
T
>
{
...
...
@@ -27,6 +28,7 @@ class ButtonSegment<T> {
required
this
.
value
,
this
.
icon
,
this
.
label
,
this
.
tooltip
,
this
.
enabled
=
true
,
})
:
assert
(
icon
!=
null
||
label
!=
null
);
...
...
@@ -41,6 +43,9 @@ class ButtonSegment<T> {
/// Optional label displayed in the segment.
final
Widget
?
label
;
/// Optional tooltip for the segment
final
String
?
tooltip
;
/// Determines if the segment is available for selection.
final
bool
enabled
;
}
...
...
@@ -335,11 +340,18 @@ class SegmentedButton<T> extends StatelessWidget {
child:
label
,
);
final
Widget
buttonWithTooltip
=
(
segment
.
tooltip
!=
null
)
?
Tooltip
(
message:
segment
.
tooltip
,
child:
button
,
)
:
button
;
return
MergeSemantics
(
child:
Semantics
(
checked:
segmentSelected
,
inMutuallyExclusiveGroup:
multiSelectionEnabled
?
null
:
true
,
child:
button
,
child:
button
WithTooltip
,
),
);
}
...
...
packages/flutter/test/material/segmented_button_test.dart
View file @
e84fa2ce
...
...
@@ -533,4 +533,59 @@ testWidgets('SegmentedButton shows checkboxes for selected segments', (WidgetTes
expect
(
overlayColor
(),
paints
..
rect
()..
rect
(
color:
theme
.
colorScheme
.
onSurface
.
withOpacity
(
0.12
)));
expect
(
material
.
textStyle
?.
color
,
theme
.
colorScheme
.
onSurface
);
});
testWidgets
(
'SegmentedButton has no tooltips by default'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
theme
=
ThemeData
(
useMaterial3:
true
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
theme
,
home:
Scaffold
(
body:
Center
(
child:
SegmentedButton
<
int
>(
segments:
const
<
ButtonSegment
<
int
>>[
ButtonSegment
<
int
>(
value:
1
,
label:
Text
(
'1'
)),
ButtonSegment
<
int
>(
value:
2
,
label:
Text
(
'2'
)),
ButtonSegment
<
int
>(
value:
3
,
label:
Text
(
'3'
),
enabled:
false
),
],
selected:
const
<
int
>{
2
},
onSelectionChanged:
(
Set
<
int
>
selected
)
{
},
),
),
),
),
);
expect
(
find
.
byType
(
Tooltip
),
findsNothing
);
});
testWidgets
(
'SegmentedButton has correct tooltips'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
theme
=
ThemeData
(
useMaterial3:
true
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
theme
,
home:
Scaffold
(
body:
Center
(
child:
SegmentedButton
<
int
>(
segments:
const
<
ButtonSegment
<
int
>>[
ButtonSegment
<
int
>(
value:
1
,
label:
Text
(
'1'
)),
ButtonSegment
<
int
>(
value:
2
,
label:
Text
(
'2'
),
tooltip:
't2'
),
ButtonSegment
<
int
>(
value:
3
,
label:
Text
(
'3'
),
tooltip:
't3'
,
enabled:
false
,
),
],
selected:
const
<
int
>{
2
},
onSelectionChanged:
(
Set
<
int
>
selected
)
{
},
),
),
),
),
);
expect
(
find
.
byType
(
Tooltip
),
findsNWidgets
(
2
));
expect
(
find
.
byTooltip
(
't2'
),
findsOneWidget
);
expect
(
find
.
byTooltip
(
't3'
),
findsOneWidget
);
});
}
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