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
946a1291
Unverified
Commit
946a1291
authored
Dec 02, 2020
by
xubaolin
Committed by
GitHub
Dec 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update [ToggleButtons] to support extend down/up vertically (#70670)
parent
60bdcf55
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
613 additions
and
244 deletions
+613
-244
toggle_buttons.dart
packages/flutter/lib/src/material/toggle_buttons.dart
+463
-244
toggle_buttons_test.dart
packages/flutter/test/material/toggle_buttons_test.dart
+150
-0
No files found.
packages/flutter/lib/src/material/toggle_buttons.dart
View file @
946a1291
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/toggle_buttons_test.dart
View file @
946a1291
...
...
@@ -1398,6 +1398,156 @@ void main() {
},
);
testWidgets
(
'Properly draws borders based on state when direction is vertical and verticalDirection is down.'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
theme
=
ThemeData
();
await
tester
.
pumpWidget
(
Material
(
child:
boilerplate
(
child:
ToggleButtons
(
direction:
Axis
.
vertical
,
verticalDirection:
VerticalDirection
.
down
,
isSelected:
const
<
bool
>[
false
,
true
,
false
],
onPressed:
(
int
index
)
{},
children:
const
<
Widget
>[
Text
(
'First child'
),
Text
(
'Second child'
),
Text
(
'Third child'
),
],
),
),
),
);
// The children should be laid out along vertical and the first child at top.
// The item height is icon height + default border width (48.0 + 1.0) pixels.
expect
(
tester
.
getCenter
(
find
.
text
(
'First child'
)),
const
Offset
(
400.0
,
251.0
));
expect
(
tester
.
getCenter
(
find
.
text
(
'Second child'
)),
const
Offset
(
400.0
,
300.0
));
expect
(
tester
.
getCenter
(
find
.
text
(
'Third child'
)),
const
Offset
(
400.0
,
349.0
));
final
List
<
RenderObject
>
toggleButtonRenderObject
=
tester
.
allRenderObjects
.
where
((
RenderObject
object
)
{
return
object
.
runtimeType
.
toString
()
==
'_SelectToggleButtonRenderObject'
;
}).
toSet
().
toList
();
// The first button paints the left, top and right sides with a path.
expect
(
toggleButtonRenderObject
[
0
],
paints
// left side, top and right - enabled.
..
path
(
style:
PaintingStyle
.
stroke
,
color:
theme
.
colorScheme
.
onSurface
.
withOpacity
(
0.12
),
strokeWidth:
_defaultBorderWidth
,
),
);
// The middle buttons paint a top side path first, followed by a
// left and right side path.
expect
(
toggleButtonRenderObject
[
1
],
paints
// top side - selected.
..
path
(
style:
PaintingStyle
.
stroke
,
color:
theme
.
colorScheme
.
onSurface
.
withOpacity
(
0.12
),
strokeWidth:
_defaultBorderWidth
,
)
// left and right - selected.
..
path
(
style:
PaintingStyle
.
stroke
,
color:
theme
.
colorScheme
.
onSurface
.
withOpacity
(
0.12
),
strokeWidth:
_defaultBorderWidth
,
),
);
// The last button paints a top side path first, followed by
// a left, bottom and right side path
expect
(
toggleButtonRenderObject
[
2
],
paints
// top side - selected, since previous button is selected.
..
path
(
style:
PaintingStyle
.
stroke
,
color:
theme
.
colorScheme
.
onSurface
.
withOpacity
(
0.12
),
strokeWidth:
_defaultBorderWidth
,
)
// left side, bottom and right - enabled.
..
path
(
style:
PaintingStyle
.
stroke
,
color:
theme
.
colorScheme
.
onSurface
.
withOpacity
(
0.12
),
strokeWidth:
_defaultBorderWidth
,
),
);
},
);
testWidgets
(
'VerticalDirection test when direction is vertical.'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Material
(
child:
boilerplate
(
child:
ToggleButtons
(
direction:
Axis
.
vertical
,
verticalDirection:
VerticalDirection
.
up
,
isSelected:
const
<
bool
>[
false
,
true
,
false
],
onPressed:
(
int
index
)
{},
children:
const
<
Widget
>[
Text
(
'First child'
),
Text
(
'Second child'
),
Text
(
'Third child'
),
],
),
),
),
);
// The children should be laid out along vertical and the last child at top.
expect
(
tester
.
getCenter
(
find
.
text
(
'Third child'
)),
const
Offset
(
400.0
,
251.0
));
expect
(
tester
.
getCenter
(
find
.
text
(
'Second child'
)),
const
Offset
(
400.0
,
300.0
));
expect
(
tester
.
getCenter
(
find
.
text
(
'First child'
)),
const
Offset
(
400.0
,
349.0
));
},
);
testWidgets
(
'ToggleButtons implements debugFillProperties'
,
(
WidgetTester
tester
)
async
{
final
DiagnosticPropertiesBuilder
builder
=
DiagnosticPropertiesBuilder
();
ToggleButtons
(
direction:
Axis
.
vertical
,
verticalDirection:
VerticalDirection
.
up
,
borderWidth:
3.0
,
color:
Colors
.
green
,
selectedBorderColor:
Colors
.
pink
,
disabledColor:
Colors
.
blue
,
disabledBorderColor:
Colors
.
yellow
,
borderRadius:
const
BorderRadius
.
all
(
Radius
.
circular
(
7.0
)),
isSelected:
const
<
bool
>[
false
,
true
,
false
],
onPressed:
(
int
index
)
{},
children:
const
<
Widget
>[
Text
(
'First child'
),
Text
(
'Second child'
),
Text
(
'Third child'
),
],
).
debugFillProperties
(
builder
);
final
List
<
String
>
description
=
builder
.
properties
.
where
((
DiagnosticsNode
node
)
=>
!
node
.
isFiltered
(
DiagnosticLevel
.
info
))
.
map
((
DiagnosticsNode
node
)
=>
node
.
toString
()).
toList
();
expect
(
description
,
<
String
>[
'Buttons are enabled'
,
'color: MaterialColor(primary value: Color(0xff4caf50))'
,
'disabledColor: MaterialColor(primary value: Color(0xff2196f3))'
,
'selectedBorderColor: MaterialColor(primary value: Color(0xffe91e63))'
,
'disabledBorderColor: MaterialColor(primary value: Color(0xffffeb3b))'
,
'borderRadius: BorderRadius.circular(7.0)'
,
'borderWidth: 3.0'
,
'direction: Axis.vertical'
,
'verticalDirection: VerticalDirection.up'
]);
});
testWidgets
(
'ToggleButtons changes mouse cursor when the button is hovered'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Material
(
...
...
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