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
91e7678f
Unverified
Commit
91e7678f
authored
Jun 03, 2020
by
William Oprandi
Committed by
GitHub
Jun 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow null value for CheckboxListTile (#58154)
parent
997a6ffc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
6 deletions
+59
-6
checkbox_list_tile.dart
packages/flutter/lib/src/material/checkbox_list_tile.dart
+20
-6
checkbox_list_tile_test.dart
packages/flutter/test/material/checkbox_list_tile_test.dart
+39
-0
No files found.
packages/flutter/lib/src/material/checkbox_list_tile.dart
View file @
91e7678f
...
...
@@ -248,11 +248,12 @@ class CheckboxListTile extends StatelessWidget {
///
/// The following arguments are required:
///
/// * [value], which determines whether the checkbox is checked, and must not
/// be null.
///
/// * [value], which determines whether the checkbox is checked. The [value]
/// can only be null if [tristate] is true.
/// * [onChanged], which is called when the value of the checkbox should
/// change. It can be set to null to disable the checkbox.
///
/// The value of [tristate] must not be null.
const
CheckboxListTile
({
Key
key
,
@required
this
.
value
,
...
...
@@ -268,7 +269,9 @@ class CheckboxListTile extends StatelessWidget {
this
.
controlAffinity
=
ListTileControlAffinity
.
platform
,
this
.
autofocus
=
false
,
this
.
contentPadding
,
})
:
assert
(
value
!=
null
),
this
.
tristate
=
false
,
})
:
assert
(
tristate
!=
null
),
assert
(
tristate
||
value
!=
null
),
assert
(
isThreeLine
!=
null
),
assert
(!
isThreeLine
||
subtitle
!=
null
),
assert
(
selected
!=
null
),
...
...
@@ -277,8 +280,6 @@ class CheckboxListTile extends StatelessWidget {
super
(
key:
key
);
/// Whether this checkbox is checked.
///
/// This property must not be null.
final
bool
value
;
/// Called when the value of the checkbox should change.
...
...
@@ -365,6 +366,18 @@ class CheckboxListTile extends StatelessWidget {
/// When the value is null, the `contentPadding` is `EdgeInsets.symmetric(horizontal: 16.0)`.
final
EdgeInsetsGeometry
contentPadding
;
/// If true the checkbox's [value] can be true, false, or null.
///
/// Checkbox displays a dash when its value is null.
///
/// When a tri-state checkbox ([tristate] is true) is tapped, its [onChanged]
/// callback will be applied to true if the current value is false, to null if
/// value is true, and to false if value is null (i.e. it cycles through false
/// => true => null => false when tapped).
///
/// If tristate is false (the default), [value] must not be null.
final
bool
tristate
;
@override
Widget
build
(
BuildContext
context
)
{
final
Widget
control
=
Checkbox
(
...
...
@@ -374,6 +387,7 @@ class CheckboxListTile extends StatelessWidget {
checkColor:
checkColor
,
materialTapTargetSize:
MaterialTapTargetSize
.
shrinkWrap
,
autofocus:
autofocus
,
tristate:
tristate
,
);
Widget
leading
,
trailing
;
switch
(
controlAffinity
)
{
...
...
packages/flutter/test/material/checkbox_list_tile_test.dart
View file @
91e7678f
...
...
@@ -144,4 +144,43 @@ void main() {
expect
(
paddingRect
.
top
,
tallerWidget
.
top
-
remainingHeight
/
2
-
18
);
expect
(
paddingRect
.
bottom
,
tallerWidget
.
bottom
+
remainingHeight
/
2
+
2
);
});
testWidgets
(
'CheckboxListTile tristate test'
,
(
WidgetTester
tester
)
async
{
bool
_value
;
await
tester
.
pumpWidget
(
Material
(
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
wrap
(
child:
CheckboxListTile
(
title:
const
Text
(
'Title'
),
tristate:
true
,
value:
_value
,
onChanged:
(
bool
value
)
{
setState
(()
{
_value
=
value
;
});
},
),
);
},
),
),
);
expect
(
tester
.
widget
<
Checkbox
>(
find
.
byType
(
Checkbox
)).
value
,
null
);
await
tester
.
tap
(
find
.
byType
(
Checkbox
));
await
tester
.
pumpAndSettle
();
expect
(
_value
,
false
);
await
tester
.
tap
(
find
.
byType
(
Checkbox
));
await
tester
.
pumpAndSettle
();
expect
(
_value
,
true
);
await
tester
.
tap
(
find
.
byType
(
Checkbox
));
await
tester
.
pumpAndSettle
();
expect
(
_value
,
null
);
});
}
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