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
7668f06f
Unverified
Commit
7668f06f
authored
Oct 12, 2020
by
Per Classon
Committed by
GitHub
Oct 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Material] Use primary color for selected rows and checkboxes in DataTable (#67919)
parent
b93f71f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
13 deletions
+81
-13
data_table.dart
packages/flutter/lib/src/material/data_table.dart
+5
-13
data_table_test.dart
packages/flutter/test/material/data_table_test.dart
+76
-0
No files found.
packages/flutter/lib/src/material/data_table.dart
View file @
7668f06f
...
...
@@ -689,12 +689,9 @@ class DataTable extends StatelessWidget {
static
const
double
_dividerThickness
=
1.0
;
static
const
Duration
_sortArrowAnimationDuration
=
Duration
(
milliseconds:
150
);
static
const
Color
_grey100Opacity
=
Color
(
0x0A000000
);
// Grey 100 as opacity instead of solid color
static
const
Color
_grey300Opacity
=
Color
(
0x1E000000
);
// Dark theme variant is just a guess.
Widget
_buildCheckbox
({
required
BuildContext
context
,
required
Color
activeColor
,
required
bool
?
checked
,
required
VoidCallback
?
onRowTap
,
required
ValueChanged
<
bool
?>?
onCheckboxChanged
,
...
...
@@ -714,7 +711,9 @@ class DataTable extends StatelessWidget {
),
child:
Center
(
child:
Checkbox
(
activeColor:
activeColor
,
// TODO(per): Remove when Checkbox has theme, https://github.com/flutter/flutter/issues/53420.
activeColor:
themeData
.
colorScheme
.
primary
,
checkColor:
themeData
.
colorScheme
.
onPrimary
,
value:
checked
,
onChanged:
onCheckboxChanged
,
tristate:
tristate
,
...
...
@@ -862,13 +861,8 @@ class DataTable extends StatelessWidget {
??
theme
.
dataTableTheme
.
dataRowColor
;
final
MaterialStateProperty
<
Color
?>
defaultRowColor
=
MaterialStateProperty
.
resolveWith
(
(
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
selected
))
{
// The color has to be transparent so you can see the ink on
// the [Material].
// TODO(perclasson): Align with Material specs, use translucent primary color: https://github.com/flutter/flutter/issues/64314.
return
(
Theme
.
of
(
context
)!.
brightness
==
Brightness
.
light
)
?
_grey100Opacity
:
_grey300Opacity
;
}
if
(
states
.
contains
(
MaterialState
.
selected
))
return
theme
.
colorScheme
.
primary
.
withOpacity
(
0.08
);
return
null
;
},
);
...
...
@@ -928,7 +922,6 @@ class DataTable extends StatelessWidget {
tableColumns
[
0
]
=
FixedColumnWidth
(
effectiveHorizontalMargin
+
Checkbox
.
width
+
effectiveHorizontalMargin
/
2.0
);
tableRows
[
0
].
children
![
0
]
=
_buildCheckbox
(
context:
context
,
activeColor:
theme
.
accentColor
,
checked:
someChecked
?
null
:
allChecked
,
onRowTap:
null
,
onCheckboxChanged:
(
bool
?
checked
)
=>
_handleSelectAll
(
checked
,
someChecked
),
...
...
@@ -939,7 +932,6 @@ class DataTable extends StatelessWidget {
for
(
final
DataRow
row
in
rows
)
{
tableRows
[
rowIndex
].
children
![
0
]
=
_buildCheckbox
(
context:
context
,
activeColor:
theme
.
accentColor
,
checked:
row
.
selected
,
onRowTap:
()
=>
row
.
onSelectChanged
!=
null
?
row
.
onSelectChanged
!(!
row
.
selected
)
:
null
,
onCheckboxChanged:
row
.
onSelectChanged
,
...
...
packages/flutter/test/material/data_table_test.dart
View file @
7668f06f
...
...
@@ -1190,6 +1190,82 @@ void main() {
await
tester
.
pumpAndSettle
(
const
Duration
(
seconds:
1
));
});
testWidgets
(
'DataRow renders default selected row colors'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
_themeData
=
ThemeData
.
light
();
Widget
buildTable
({
bool
selected
=
false
})
{
return
MaterialApp
(
theme:
_themeData
,
home:
Material
(
child:
DataTable
(
columns:
const
<
DataColumn
>[
DataColumn
(
label:
Text
(
'Column1'
),
),
],
rows:
<
DataRow
>[
DataRow
(
onSelectChanged:
(
bool
?
checked
)
{},
selected:
selected
,
cells:
const
<
DataCell
>[
DataCell
(
Text
(
'Content1'
)),
],
),
],
),
),
);
}
BoxDecoration
lastTableRowBoxDecoration
()
{
final
Table
table
=
tester
.
widget
(
find
.
byType
(
Table
));
final
TableRow
tableRow
=
table
.
children
.
last
;
return
tableRow
.
decoration
!
as
BoxDecoration
;
}
await
tester
.
pumpWidget
(
buildTable
(
selected:
false
));
expect
(
lastTableRowBoxDecoration
().
color
,
null
);
await
tester
.
pumpWidget
(
buildTable
(
selected:
true
));
expect
(
lastTableRowBoxDecoration
().
color
,
_themeData
.
colorScheme
.
primary
.
withOpacity
(
0.08
),
);
});
testWidgets
(
'DataRow renders checkbox with colors from Theme'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
_themeData
=
ThemeData
.
light
();
Widget
buildTable
()
{
return
MaterialApp
(
theme:
_themeData
,
home:
Material
(
child:
DataTable
(
columns:
const
<
DataColumn
>[
DataColumn
(
label:
Text
(
'Column1'
),
),
],
rows:
<
DataRow
>[
DataRow
(
onSelectChanged:
(
bool
?
checked
)
{},
cells:
const
<
DataCell
>[
DataCell
(
Text
(
'Content1'
)),
],
),
],
),
),
);
}
Checkbox
lastCheckbox
()
{
return
tester
.
widgetList
<
Checkbox
>(
find
.
byType
(
Checkbox
)).
last
;
}
await
tester
.
pumpWidget
(
buildTable
());
expect
(
lastCheckbox
().
activeColor
,
_themeData
.
colorScheme
.
primary
);
expect
(
lastCheckbox
().
checkColor
,
_themeData
.
colorScheme
.
onPrimary
);
});
testWidgets
(
'DataRow renders custom colors when selected'
,
(
WidgetTester
tester
)
async
{
const
Color
selectedColor
=
Colors
.
green
;
const
Color
defaultColor
=
Colors
.
red
;
...
...
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