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
2c59a3a7
Unverified
Commit
2c59a3a7
authored
Oct 14, 2020
by
Darren Austin
Committed by
GitHub
Oct 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate Switch tests to null safety. (#68133)
parent
f2d5f1f6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
25 deletions
+31
-25
switch.dart
packages/flutter/lib/src/material/switch.dart
+15
-5
switch_list_tile.dart
packages/flutter/lib/src/material/switch_list_tile.dart
+1
-1
switch_list_tile_test.dart
packages/flutter/test/material/switch_list_tile_test.dart
+5
-7
switch_test.dart
packages/flutter/test/material/switch_test.dart
+10
-12
No files found.
packages/flutter/lib/src/material/switch.dart
View file @
2c59a3a7
...
...
@@ -149,7 +149,7 @@ class Switch extends StatefulWidget {
/// },
/// )
/// ```
final
ValueChanged
<
bool
?
>?
onChanged
;
final
ValueChanged
<
bool
>?
onChanged
;
/// The color to use when this switch is on.
///
...
...
@@ -440,7 +440,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
final
Color
activeTrackColor
;
final
Color
inactiveTrackColor
;
final
ImageConfiguration
configuration
;
final
ValueChanged
<
bool
?
>?
onChanged
;
final
ValueChanged
<
bool
>?
onChanged
;
final
BoxConstraints
additionalConstraints
;
final
DragStartBehavior
dragStartBehavior
;
final
bool
hasFocus
;
...
...
@@ -463,7 +463,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
activeTrackColor:
activeTrackColor
,
inactiveTrackColor:
inactiveTrackColor
,
configuration:
configuration
,
onChanged:
onChanged
,
onChanged:
onChanged
!=
null
?
_handleValueChanged
:
null
,
textDirection:
Directionality
.
of
(
context
)!,
additionalConstraints:
additionalConstraints
,
hasFocus:
hasFocus
,
...
...
@@ -487,7 +487,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
..
activeTrackColor
=
activeTrackColor
..
inactiveTrackColor
=
inactiveTrackColor
..
configuration
=
configuration
..
onChanged
=
onChanged
..
onChanged
=
onChanged
!=
null
?
_handleValueChanged
:
null
..
textDirection
=
Directionality
.
of
(
context
)!
..
additionalConstraints
=
additionalConstraints
..
dragStartBehavior
=
dragStartBehavior
...
...
@@ -495,6 +495,17 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
..
hovering
=
hovering
..
vsync
=
state
;
}
void
_handleValueChanged
(
bool
?
value
)
{
// Wrap the onChanged callback because the RenderToggleable supports tri-state
// values (i.e. value can be null), but the Switch doesn't. We pass false
// for the tristate param to RenderToggleable, so value should never
// be null.
assert
(
value
!=
null
);
if
(
onChanged
!=
null
)
{
onChanged
!(
value
!);
}
}
}
class
_RenderSwitch
extends
RenderToggleable
{
...
...
@@ -650,7 +661,6 @@ class _RenderSwitch extends RenderToggleable {
}
}
@override
void
detach
()
{
_cachedThumbPainter
?.
dispose
();
...
...
packages/flutter/lib/src/material/switch_list_tile.dart
View file @
2c59a3a7
...
...
@@ -346,7 +346,7 @@ class SwitchListTile extends StatelessWidget {
/// title: Text('Selection'),
/// )
/// ```
final
ValueChanged
<
bool
?
>?
onChanged
;
final
ValueChanged
<
bool
>?
onChanged
;
/// The color to use when this switch is on.
///
...
...
packages/flutter/test/material/switch_list_tile_test.dart
View file @
2c59a3a7
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
...
...
@@ -12,7 +10,7 @@ import '../rendering/mock_canvas.dart';
import
'../widgets/semantics_tester.dart'
;
Widget
wrap
(
{
Widget
child
})
{
Widget
wrap
(
{
required
Widget
child
})
{
return
MediaQuery
(
data:
const
MediaQueryData
(),
child:
Directionality
(
...
...
@@ -51,14 +49,14 @@ void main() {
),
CheckboxListTile
(
value:
true
,
onChanged:
(
bool
value
)
{
},
onChanged:
(
bool
?
value
)
{
},
title:
const
Text
(
'BBB'
),
secondary:
const
Text
(
'bbb'
),
),
RadioListTile
<
bool
>(
value:
true
,
groupValue:
false
,
onChanged:
(
bool
value
)
{
},
onChanged:
(
bool
?
value
)
{
},
title:
const
Text
(
'CCC'
),
secondary:
const
Text
(
'ccc'
),
),
...
...
@@ -278,7 +276,7 @@ void main() {
);
await
tester
.
pump
();
expect
(
Focus
.
of
(
childKey
.
currentContext
,
nullOk:
true
)
.
hasPrimaryFocus
,
isTrue
);
expect
(
Focus
.
of
(
childKey
.
currentContext
!)!
.
hasPrimaryFocus
,
isTrue
);
await
tester
.
pumpWidget
(
MaterialApp
(
...
...
@@ -298,7 +296,7 @@ void main() {
);
await
tester
.
pump
();
expect
(
Focus
.
of
(
childKey
.
currentContext
,
nullOk:
true
)
.
hasPrimaryFocus
,
isFalse
);
expect
(
Focus
.
of
(
childKey
.
currentContext
!)!
.
hasPrimaryFocus
,
isFalse
);
});
testWidgets
(
'SwitchListTile controlAffinity test'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/material/switch_test.dart
View file @
2c59a3a7
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
...
...
@@ -318,7 +316,7 @@ void main() {
Material
.
of
(
tester
.
element
(
find
.
byType
(
Switch
))),
paints
..
rrect
(
color:
Colors
.
blue
[
600
].
withAlpha
(
0x80
),
color:
Colors
.
blue
[
600
]
!
.
withAlpha
(
0x80
),
rrect:
RRect
.
fromLTRBR
(
383.5
,
293.0
,
416.5
,
307.0
,
const
Radius
.
circular
(
7.0
)))
..
circle
(
color:
const
Color
(
0x33000000
))
...
...
@@ -608,10 +606,10 @@ void main() {
expect
(
value
,
true
);
expect
(
semanticEvent
,
<
String
,
dynamic
>{
'type'
:
'tap'
,
'nodeId'
:
object
.
debugSemantics
.
id
,
'nodeId'
:
object
.
debugSemantics
!
.
id
,
'data'
:
<
String
,
dynamic
>{},
});
expect
(
object
.
debugSemantics
.
getSemanticsData
().
hasAction
(
SemanticsAction
.
tap
),
true
);
expect
(
object
.
debugSemantics
!
.
getSemanticsData
().
hasAction
(
SemanticsAction
.
tap
),
true
);
semanticsTester
.
dispose
();
SystemChannels
.
accessibility
.
setMockMessageHandler
(
null
);
...
...
@@ -658,10 +656,10 @@ void main() {
expect
(
value
,
true
);
expect
(
semanticEvent
,
<
String
,
dynamic
>{
'type'
:
'tap'
,
'nodeId'
:
object
.
debugSemantics
.
id
,
'nodeId'
:
object
.
debugSemantics
!
.
id
,
'data'
:
<
String
,
dynamic
>{},
});
expect
(
object
.
debugSemantics
.
getSemanticsData
().
hasAction
(
SemanticsAction
.
tap
),
true
);
expect
(
object
.
debugSemantics
!
.
getSemanticsData
().
hasAction
(
SemanticsAction
.
tap
),
true
);
semanticsTester
.
dispose
();
SystemChannels
.
accessibility
.
setMockMessageHandler
(
null
);
...
...
@@ -943,7 +941,7 @@ void main() {
await
tester
.
pump
();
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
text
);
expect
(
RendererBinding
.
instance
!
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
text
);
// Test Switch() constructor
await
tester
.
pumpWidget
(
...
...
@@ -967,7 +965,7 @@ void main() {
);
await
gesture
.
moveTo
(
tester
.
getCenter
(
find
.
byType
(
Switch
)));
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
text
);
expect
(
RendererBinding
.
instance
!
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
text
);
// Test default cursor
await
tester
.
pumpWidget
(
...
...
@@ -989,7 +987,7 @@ void main() {
),
);
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
click
);
expect
(
RendererBinding
.
instance
!
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
click
);
// Test default cursor when disabled
await
tester
.
pumpWidget
(
...
...
@@ -1011,7 +1009,7 @@ void main() {
),
);
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
basic
);
expect
(
RendererBinding
.
instance
!
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
basic
);
await
tester
.
pumpAndSettle
();
});
...
...
@@ -1020,7 +1018,7 @@ void main() {
// Regression test for https://github.com/flutter/flutter/issues/61247.
bool
value
=
true
;
bool
enabled
=
true
;
StateSetter
stateSetter
;
late
StateSetter
stateSetter
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
...
...
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