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
db5a62b0
Unverified
Commit
db5a62b0
authored
Jul 07, 2020
by
Per Classon
Committed by
GitHub
Jul 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support customizing colors for rows in DataTable (#60764)
parent
70a3dc0c
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
262 additions
and
17 deletions
+262
-17
data_table.dart
packages/flutter/lib/src/material/data_table.dart
+120
-16
ink_well.dart
packages/flutter/lib/src/material/ink_well.dart
+1
-1
data_table_test.dart
packages/flutter/test/material/data_table_test.dart
+141
-0
No files found.
packages/flutter/lib/src/material/data_table.dart
View file @
db5a62b0
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/material/ink_well.dart
View file @
db5a62b0
...
...
@@ -503,7 +503,7 @@ class InkResponse extends StatelessWidget {
/// See also:
///
/// * The Material Design specification for overlay colors and how they
///
to
a component's state:
///
match
a component's state:
/// <https://material.io/design/interaction/states.html#anatomy>.
final
MaterialStateProperty
<
Color
>
overlayColor
;
...
...
packages/flutter/test/material/data_table_test.dart
View file @
db5a62b0
...
...
@@ -8,6 +8,7 @@ import 'package:flutter/gestures.dart';
import
'package:flutter/material.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'../rendering/mock_canvas.dart'
;
import
'data_table_test_utils.dart'
;
void
main
(
)
{
...
...
@@ -1036,4 +1037,144 @@ void main() {
// after the view is destroyed, which causes exceptions.
await
tester
.
pumpAndSettle
(
const
Duration
(
seconds:
1
));
});
testWidgets
(
'DataRow renders custom colors when selected'
,
(
WidgetTester
tester
)
async
{
const
Color
selectedColor
=
Colors
.
green
;
const
Color
defaultColor
=
Colors
.
red
;
Widget
buildTable
({
bool
selected
=
false
})
{
return
Material
(
child:
DataTable
(
columns:
const
<
DataColumn
>[
DataColumn
(
label:
Text
(
'Column1'
),
),
],
rows:
<
DataRow
>[
DataRow
(
selected:
selected
,
color:
MaterialStateProperty
.
resolveWith
<
Color
>(
(
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
selected
))
return
selectedColor
;
return
defaultColor
;
},
),
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
(
MaterialApp
(
home:
buildTable
(),
));
expect
(
lastTableRowBoxDecoration
().
color
,
defaultColor
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
buildTable
(
selected:
true
),
));
expect
(
lastTableRowBoxDecoration
().
color
,
selectedColor
);
});
testWidgets
(
'DataRow renders custom colors when disabled'
,
(
WidgetTester
tester
)
async
{
const
Color
disabledColor
=
Colors
.
grey
;
const
Color
defaultColor
=
Colors
.
red
;
Widget
buildTable
({
bool
disabled
=
false
})
{
return
Material
(
child:
DataTable
(
columns:
const
<
DataColumn
>[
DataColumn
(
label:
Text
(
'Column1'
),
),
],
rows:
<
DataRow
>[
DataRow
(
cells:
const
<
DataCell
>[
DataCell
(
Text
(
'Content1'
)),
],
onSelectChanged:
(
bool
value
)
{},
),
DataRow
(
color:
MaterialStateProperty
.
resolveWith
<
Color
>(
(
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
disabled
))
return
disabledColor
;
return
defaultColor
;
},
),
cells:
const
<
DataCell
>[
DataCell
(
Text
(
'Content2'
)),
],
onSelectChanged:
disabled
?
null
:
(
bool
value
)
{},
),
],
),
);
}
BoxDecoration
lastTableRowBoxDecoration
()
{
final
Table
table
=
tester
.
widget
(
find
.
byType
(
Table
));
final
TableRow
tableRow
=
table
.
children
.
last
;
return
tableRow
.
decoration
as
BoxDecoration
;
}
await
tester
.
pumpWidget
(
MaterialApp
(
home:
buildTable
(),
));
expect
(
lastTableRowBoxDecoration
().
color
,
defaultColor
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
buildTable
(
disabled:
true
),
));
expect
(
lastTableRowBoxDecoration
().
color
,
disabledColor
);
});
testWidgets
(
'DataRow renders custom colors when pressed'
,
(
WidgetTester
tester
)
async
{
const
Color
pressedColor
=
Color
(
0xff4caf50
);
Widget
buildTable
()
{
return
DataTable
(
columns:
const
<
DataColumn
>[
DataColumn
(
label:
Text
(
'Column1'
),
),
],
rows:
<
DataRow
>[
DataRow
(
color:
MaterialStateProperty
.
resolveWith
<
Color
>(
(
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
pressed
))
return
pressedColor
;
return
Colors
.
transparent
;
},
),
onSelectChanged:
(
bool
value
)
{},
cells:
const
<
DataCell
>[
DataCell
(
Text
(
'Content1'
)),
],
),
]
);
}
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
buildTable
()),
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'Content1'
)));
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
// splash is well underway
final
RenderBox
box
=
Material
.
of
(
tester
.
element
(
find
.
byType
(
InkWell
)))
as
RenderBox
;
expect
(
box
,
paints
..
circle
(
x:
64.0
,
y:
24.0
,
color:
pressedColor
));
await
gesture
.
up
();
});
}
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