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
8b63c654
Unverified
Commit
8b63c654
authored
May 27, 2020
by
Ayush Bherwani
Committed by
GitHub
May 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[SwitchListTile] adds controlAffinity property (#58037)
parent
3373a404
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
5 deletions
+67
-5
AUTHORS
AUTHORS
+1
-0
list_tile.dart
packages/flutter/lib/src/material/list_tile.dart
+1
-0
switch_list_tile.dart
packages/flutter/lib/src/material/switch_list_tile.dart
+25
-5
switch_list_tile_test.dart
packages/flutter/test/material/switch_list_tile_test.dart
+40
-0
No files found.
AUTHORS
View file @
8b63c654
...
...
@@ -56,3 +56,4 @@ Michael Lee <ckmichael8@gmail.com>
Katarina Sheremet <katarina@sheremet.ch>
Nicolas Schneider <nioncode+git@gmail.com>
Mikhail Zotyev <mbixjkee1392@gmail.com>
Ayush Bherwani <ayush.bherwani1998@gmail.com>
packages/flutter/lib/src/material/list_tile.dart
View file @
8b63c654
...
...
@@ -148,6 +148,7 @@ class ListTileTheme extends InheritedTheme {
///
/// * [CheckboxListTile], which combines a [ListTile] with a [Checkbox].
/// * [RadioListTile], which combines a [ListTile] with a [Radio] button.
/// * [SwitchListTile], which combines a [ListTile] with a [Switch].
enum
ListTileControlAffinity
{
/// Position the control on the leading edge, and the secondary widget, if
/// any, on the trailing edge.
...
...
packages/flutter/lib/src/material/switch_list_tile.dart
View file @
8b63c654
...
...
@@ -39,9 +39,8 @@ enum _SwitchListTileType { material, adaptive }
/// appear selected when the switch is on, pass the same value to both.
///
/// The switch is shown on the right by default in left-to-right languages (i.e.
/// in the [ListTile.trailing] slot). The [secondary] widget is placed in the
/// [ListTile.leading] slot. This cannot be changed; there is not sufficient
/// space in a [ListTile]'s [ListTile.leading] slot for a [Switch].
/// in the [ListTile.trailing] slot) which can be changed using [controlAffinity].
/// The [secondary] widget is placed in the [ListTile.leading] slot.
///
/// To show the [SwitchListTile] as disabled, pass null as the [onChanged]
/// callback.
...
...
@@ -273,6 +272,7 @@ class SwitchListTile extends StatelessWidget {
this
.
secondary
,
this
.
selected
=
false
,
this
.
autofocus
=
false
,
this
.
controlAffinity
=
ListTileControlAffinity
.
platform
,
})
:
_switchListTileType
=
_SwitchListTileType
.
material
,
assert
(
value
!=
null
),
assert
(
isThreeLine
!=
null
),
...
...
@@ -307,6 +307,7 @@ class SwitchListTile extends StatelessWidget {
this
.
secondary
,
this
.
selected
=
false
,
this
.
autofocus
=
false
,
this
.
controlAffinity
=
ListTileControlAffinity
.
platform
,
})
:
_switchListTileType
=
_SwitchListTileType
.
adaptive
,
assert
(
value
!=
null
),
assert
(
isThreeLine
!=
null
),
...
...
@@ -429,6 +430,11 @@ class SwitchListTile extends StatelessWidget {
/// If adaptive, creates the switch with [Switch.adaptive].
final
_SwitchListTileType
_switchListTileType
;
/// Defines the position of control and [secondary], relative to text.
///
/// By default, the value of `controlAffinity` is [ListTileControlAffinity.platform].
final
ListTileControlAffinity
controlAffinity
;
@override
Widget
build
(
BuildContext
context
)
{
Widget
control
;
...
...
@@ -462,14 +468,28 @@ class SwitchListTile extends StatelessWidget {
autofocus:
autofocus
,
);
}
Widget
leading
,
trailing
;
switch
(
controlAffinity
)
{
case
ListTileControlAffinity
.
leading
:
leading
=
control
;
trailing
=
secondary
;
break
;
case
ListTileControlAffinity
.
trailing
:
case
ListTileControlAffinity
.
platform
:
leading
=
secondary
;
trailing
=
control
;
break
;
}
return
MergeSemantics
(
child:
ListTileTheme
.
merge
(
selectedColor:
activeColor
??
Theme
.
of
(
context
).
accentColor
,
child:
ListTile
(
leading:
secondary
,
leading:
leading
,
title:
title
,
subtitle:
subtitle
,
trailing:
control
,
trailing:
trailing
,
isThreeLine:
isThreeLine
,
dense:
dense
,
contentPadding:
contentPadding
,
...
...
packages/flutter/test/material/switch_list_tile_test.dart
View file @
8b63c654
...
...
@@ -298,4 +298,44 @@ void main() {
await
tester
.
pump
();
expect
(
Focus
.
of
(
childKey
.
currentContext
,
nullOk:
true
).
hasPrimaryFocus
,
isFalse
);
});
testWidgets
(
'SwitchListTile controlAffinity test'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
Material
(
child:
SwitchListTile
(
value:
true
,
onChanged:
null
,
secondary:
Icon
(
Icons
.
info
),
title:
Text
(
'Title'
),
controlAffinity:
ListTileControlAffinity
.
leading
,
),
),
));
final
ListTile
listTile
=
tester
.
widget
(
find
.
byType
(
ListTile
));
// When controlAffinity is ListTileControlAffinity.leading, the position of
// Switch is at leading edge and SwitchListTile.secondary at trailing edge.
expect
(
listTile
.
leading
.
runtimeType
,
Switch
);
expect
(
listTile
.
trailing
.
runtimeType
,
Icon
);
});
testWidgets
(
'SwitchListTile controlAffinity default value test'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
Material
(
child:
SwitchListTile
(
value:
true
,
onChanged:
null
,
secondary:
Icon
(
Icons
.
info
),
title:
Text
(
'Title'
),
),
),
));
final
ListTile
listTile
=
tester
.
widget
(
find
.
byType
(
ListTile
));
// By default, value of controlAffinity is ListTileControlAffinity.platform,
// where the position of SwitchListTile.secondary is at leading edge and Switch
// at trailing edge. This also covers test for ListTileControlAffinity.trailing.
expect
(
listTile
.
leading
.
runtimeType
,
Icon
);
expect
(
listTile
.
trailing
.
runtimeType
,
Switch
);
});
}
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