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
9cb7ac13
Unverified
Commit
9cb7ac13
authored
Jul 14, 2020
by
Ayush Bherwani
Committed by
GitHub
Jul 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ListTile] adds new properties to customize the tile color (#61347)
parent
5c9d09f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
15 deletions
+116
-15
list_tile.dart
packages/flutter/lib/src/material/list_tile.dart
+40
-15
list_tile_test.dart
packages/flutter/test/material/list_tile_test.dart
+76
-0
No files found.
packages/flutter/lib/src/material/list_tile.dart
View file @
9cb7ac13
...
...
@@ -658,6 +658,8 @@ class ListTile extends StatelessWidget {
this
.
hoverColor
,
this
.
focusNode
,
this
.
autofocus
=
false
,
this
.
tileColor
,
this
.
selectedTileColor
,
})
:
assert
(
isThreeLine
!=
null
),
assert
(
enabled
!=
null
),
assert
(
selected
!=
null
),
...
...
@@ -808,6 +810,16 @@ class ListTile extends StatelessWidget {
/// {@macro flutter.widgets.Focus.autofocus}
final
bool
autofocus
;
/// Defines the background color of `ListTile when [selected] is false.
///
/// By default, the value of `tileColor` is [Colors.transparent].
final
Color
tileColor
;
/// Defines the background color of `ListTile` when [selected] is true.
///
/// By default, the value of `selectedListColor` is [Colors.transparent].
final
Color
selectedTileColor
;
/// Add a one pixel border in between each tile. If color isn't specified the
/// [ThemeData.dividerColor] of the context's [Theme] is used.
///
...
...
@@ -913,6 +925,16 @@ class ListTile extends StatelessWidget {
:
style
.
copyWith
(
color:
color
);
}
Color
_tileBackgroundColor
()
{
if
(!
selected
&&
tileColor
!=
null
)
return
tileColor
;
if
(
selected
&&
selectedTileColor
!=
null
)
return
selectedTileColor
;
return
Colors
.
transparent
;
}
@override
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
...
...
@@ -984,21 +1006,24 @@ class ListTile extends StatelessWidget {
child:
Semantics
(
selected:
selected
,
enabled:
enabled
,
child:
SafeArea
(
top:
false
,
bottom:
false
,
minimum:
resolvedContentPadding
,
child:
_ListTile
(
leading:
leadingIcon
,
title:
titleText
,
subtitle:
subtitleText
,
trailing:
trailingIcon
,
isDense:
_isDenseLayout
(
tileTheme
),
visualDensity:
visualDensity
??
theme
.
visualDensity
,
isThreeLine:
isThreeLine
,
textDirection:
textDirection
,
titleBaselineType:
titleStyle
.
textBaseline
,
subtitleBaselineType:
subtitleStyle
?.
textBaseline
,
child:
ColoredBox
(
color:
_tileBackgroundColor
(),
child:
SafeArea
(
top:
false
,
bottom:
false
,
minimum:
resolvedContentPadding
,
child:
_ListTile
(
leading:
leadingIcon
,
title:
titleText
,
subtitle:
subtitleText
,
trailing:
trailingIcon
,
isDense:
_isDenseLayout
(
tileTheme
),
visualDensity:
visualDensity
??
theme
.
visualDensity
,
isThreeLine:
isThreeLine
,
textDirection:
textDirection
,
titleBaselineType:
titleStyle
.
textBaseline
,
subtitleBaselineType:
subtitleStyle
?.
textBaseline
,
),
),
),
),
...
...
packages/flutter/test/material/list_tile_test.dart
View file @
9cb7ac13
...
...
@@ -1534,4 +1534,80 @@ void main() {
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
basic
);
});
testWidgets
(
'ListTile respects tileColor & selectedTileColor'
,
(
WidgetTester
tester
)
async
{
bool
isSelected
=
false
;
const
Color
selectedTileColor
=
Colors
.
red
;
const
Color
tileColor
=
Colors
.
green
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
Center
(
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
ListTile
(
selected:
isSelected
,
selectedTileColor:
selectedTileColor
,
tileColor:
tileColor
,
onTap:
()
{
setState
(()=>
isSelected
=
!
isSelected
);
},
title:
const
Text
(
'Title'
),
);
},
),
),
),
),
);
// Initially, when isSelected is false, the ListTile should respect tileColor.
ColoredBox
coloredBox
=
tester
.
widget
(
find
.
byType
(
ColoredBox
));
expect
(
coloredBox
.
color
,
tileColor
);
// Tap on tile to change isSelected.
await
tester
.
tap
(
find
.
byType
(
ListTile
));
await
tester
.
pumpAndSettle
();
// When isSelected is true, the ListTile should respect selectedTileColor.
coloredBox
=
tester
.
widget
(
find
.
byType
(
ColoredBox
));
expect
(
coloredBox
.
color
,
selectedTileColor
);
});
testWidgets
(
'ListTile default tile color'
,
(
WidgetTester
tester
)
async
{
bool
isSelected
=
false
;
const
Color
defaultColor
=
Colors
.
transparent
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
Center
(
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
ListTile
(
selected:
isSelected
,
onTap:
()
{
setState
(()=>
isSelected
=
!
isSelected
);
},
title:
const
Text
(
'Title'
),
);
},
),
),
),
),
);
ColoredBox
coloredBox
=
tester
.
widget
(
find
.
byType
(
ColoredBox
));
expect
(
coloredBox
.
color
,
defaultColor
);
// Tap on tile to change isSelected.
await
tester
.
tap
(
find
.
byType
(
ListTile
));
await
tester
.
pumpAndSettle
();
coloredBox
=
tester
.
widget
(
find
.
byType
(
ColoredBox
));
expect
(
isSelected
,
isTrue
);
expect
(
coloredBox
.
color
,
defaultColor
);
});
}
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