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
a9c2f8b9
Unverified
Commit
a9c2f8b9
authored
Nov 29, 2022
by
Mohammed CHAHBOUN
Committed by
GitHub
Nov 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add onFocusChange property for ListTile widget (#111498)
parent
50f101ac
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
182 additions
and
0 deletions
+182
-0
checkbox_list_tile.dart
packages/flutter/lib/src/material/checkbox_list_tile.dart
+5
-0
ink_well.dart
packages/flutter/lib/src/material/ink_well.dart
+2
-0
list_tile.dart
packages/flutter/lib/src/material/list_tile.dart
+5
-0
radio_list_tile.dart
packages/flutter/lib/src/material/radio_list_tile.dart
+5
-0
switch.dart
packages/flutter/lib/src/material/switch.dart
+10
-0
switch_list_tile.dart
packages/flutter/lib/src/material/switch_list_tile.dart
+8
-0
toggleable.dart
packages/flutter/lib/src/material/toggleable.dart
+2
-0
checkbox_list_tile_test.dart
packages/flutter/test/material/checkbox_list_tile_test.dart
+29
-0
list_tile_test.dart
packages/flutter/test/material/list_tile_test.dart
+28
-0
radio_list_tile_test.dart
packages/flutter/test/material/radio_list_tile_test.dart
+30
-0
switch_list_tile_test.dart
packages/flutter/test/material/switch_list_tile_test.dart
+58
-0
No files found.
packages/flutter/lib/src/material/checkbox_list_tile.dart
View file @
a9c2f8b9
...
...
@@ -176,6 +176,7 @@ class CheckboxListTile extends StatelessWidget {
this
.
side
,
this
.
visualDensity
,
this
.
focusNode
,
this
.
onFocusChange
,
this
.
enableFeedback
,
})
:
assert
(
tristate
!=
null
),
assert
(
tristate
||
value
!=
null
),
...
...
@@ -320,6 +321,9 @@ class CheckboxListTile extends StatelessWidget {
/// {@macro flutter.widgets.Focus.focusNode}
final
FocusNode
?
focusNode
;
/// {@macro flutter.material.inkwell.onFocusChange}
final
ValueChanged
<
bool
>?
onFocusChange
;
/// {@macro flutter.material.ListTile.enableFeedback}
///
/// See also:
...
...
@@ -401,6 +405,7 @@ class CheckboxListTile extends StatelessWidget {
tileColor:
tileColor
,
visualDensity:
visualDensity
,
focusNode:
focusNode
,
onFocusChange:
onFocusChange
,
enableFeedback:
enableFeedback
,
),
);
...
...
packages/flutter/lib/src/material/ink_well.dart
View file @
a9c2f8b9
...
...
@@ -559,10 +559,12 @@ class InkResponse extends StatelessWidget {
/// duplication of information.
final
bool
excludeFromSemantics
;
/// {@template flutter.material.inkwell.onFocusChange}
/// Handler called when the focus changes.
///
/// Called with true if this widget's node gains focus, and false if it loses
/// focus.
/// {@endtemplate}
final
ValueChanged
<
bool
>?
onFocusChange
;
/// {@macro flutter.widgets.Focus.autofocus}
...
...
packages/flutter/lib/src/material/list_tile.dart
View file @
a9c2f8b9
...
...
@@ -282,6 +282,7 @@ class ListTile extends StatelessWidget {
this
.
enabled
=
true
,
this
.
onTap
,
this
.
onLongPress
,
this
.
onFocusChange
,
this
.
mouseCursor
,
this
.
selected
=
false
,
this
.
focusColor
,
...
...
@@ -456,6 +457,9 @@ class ListTile extends StatelessWidget {
/// Inoperative if [enabled] is false.
final
GestureLongPressCallback
?
onLongPress
;
/// {@macro flutter.material.inkwell.onFocusChange}
final
ValueChanged
<
bool
>?
onFocusChange
;
/// {@template flutter.material.ListTile.mouseCursor}
/// The cursor for a mouse pointer when it enters or is hovering over the
/// widget.
...
...
@@ -738,6 +742,7 @@ class ListTile extends StatelessWidget {
customBorder:
shape
??
tileTheme
.
shape
,
onTap:
enabled
?
onTap
:
null
,
onLongPress:
enabled
?
onLongPress
:
null
,
onFocusChange:
onFocusChange
,
mouseCursor:
effectiveMouseCursor
,
canRequestFocus:
enabled
,
focusNode:
focusNode
,
...
...
packages/flutter/lib/src/material/radio_list_tile.dart
View file @
a9c2f8b9
...
...
@@ -171,6 +171,7 @@ class RadioListTile<T> extends StatelessWidget {
this
.
selectedTileColor
,
this
.
visualDensity
,
this
.
focusNode
,
this
.
onFocusChange
,
this
.
enableFeedback
,
})
:
assert
(
toggleable
!=
null
),
assert
(
isThreeLine
!=
null
),
...
...
@@ -320,6 +321,9 @@ class RadioListTile<T> extends StatelessWidget {
/// {@macro flutter.widgets.Focus.focusNode}
final
FocusNode
?
focusNode
;
/// {@macro flutter.material.inkwell.onFocusChange}
final
ValueChanged
<
bool
>?
onFocusChange
;
/// {@macro flutter.material.ListTile.enableFeedback}
///
/// See also:
...
...
@@ -385,6 +389,7 @@ class RadioListTile<T> extends StatelessWidget {
contentPadding:
contentPadding
,
visualDensity:
visualDensity
,
focusNode:
focusNode
,
onFocusChange:
onFocusChange
,
enableFeedback:
enableFeedback
,
),
);
...
...
packages/flutter/lib/src/material/switch.dart
View file @
a9c2f8b9
...
...
@@ -114,6 +114,7 @@ class Switch extends StatelessWidget {
this
.
overlayColor
,
this
.
splashRadius
,
this
.
focusNode
,
this
.
onFocusChange
,
this
.
autofocus
=
false
,
})
:
_switchType
=
_SwitchType
.
material
,
assert
(
dragStartBehavior
!=
null
),
...
...
@@ -158,6 +159,7 @@ class Switch extends StatelessWidget {
this
.
overlayColor
,
this
.
splashRadius
,
this
.
focusNode
,
this
.
onFocusChange
,
this
.
autofocus
=
false
,
})
:
assert
(
autofocus
!=
null
),
assert
(
activeThumbImage
!=
null
||
onActiveThumbImageError
==
null
),
...
...
@@ -455,6 +457,9 @@ class Switch extends StatelessWidget {
/// {@macro flutter.widgets.Focus.focusNode}
final
FocusNode
?
focusNode
;
/// {@macro flutter.material.inkwell.onFocusChange}
final
ValueChanged
<
bool
>?
onFocusChange
;
/// {@macro flutter.widgets.Focus.autofocus}
final
bool
autofocus
;
...
...
@@ -478,6 +483,7 @@ class Switch extends StatelessWidget {
final
Size
size
=
_getSwitchSize
(
context
);
return
Focus
(
focusNode:
focusNode
,
onFocusChange:
onFocusChange
,
autofocus:
autofocus
,
child:
Container
(
width:
size
.
width
,
// Same size as the Material switch.
...
...
@@ -518,6 +524,7 @@ class Switch extends StatelessWidget {
overlayColor:
overlayColor
,
splashRadius:
splashRadius
,
focusNode:
focusNode
,
onFocusChange:
onFocusChange
,
autofocus:
autofocus
,
);
}
...
...
@@ -577,6 +584,7 @@ class _MaterialSwitch extends StatefulWidget {
this
.
overlayColor
,
this
.
splashRadius
,
this
.
focusNode
,
this
.
onFocusChange
,
this
.
autofocus
=
false
,
})
:
assert
(
dragStartBehavior
!=
null
),
assert
(
activeThumbImage
!=
null
||
onActiveThumbImageError
==
null
),
...
...
@@ -603,6 +611,7 @@ class _MaterialSwitch extends StatefulWidget {
final
MaterialStateProperty
<
Color
?>?
overlayColor
;
final
double
?
splashRadius
;
final
FocusNode
?
focusNode
;
final
Function
(
bool
)?
onFocusChange
;
final
bool
autofocus
;
final
Size
size
;
...
...
@@ -822,6 +831,7 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta
child:
buildToggleable
(
mouseCursor:
effectiveMouseCursor
,
focusNode:
widget
.
focusNode
,
onFocusChange:
widget
.
onFocusChange
,
autofocus:
widget
.
autofocus
,
size:
widget
.
size
,
painter:
_painter
...
...
packages/flutter/lib/src/material/switch_list_tile.dart
View file @
a9c2f8b9
...
...
@@ -176,6 +176,7 @@ class SwitchListTile extends StatelessWidget {
this
.
selectedTileColor
,
this
.
visualDensity
,
this
.
focusNode
,
this
.
onFocusChange
,
this
.
enableFeedback
,
this
.
hoverColor
,
})
:
_switchListTileType
=
_SwitchListTileType
.
material
,
...
...
@@ -221,6 +222,7 @@ class SwitchListTile extends StatelessWidget {
this
.
selectedTileColor
,
this
.
visualDensity
,
this
.
focusNode
,
this
.
onFocusChange
,
this
.
enableFeedback
,
this
.
hoverColor
,
})
:
_switchListTileType
=
_SwitchListTileType
.
adaptive
,
...
...
@@ -368,6 +370,9 @@ class SwitchListTile extends StatelessWidget {
/// {@macro flutter.widgets.Focus.focusNode}
final
FocusNode
?
focusNode
;
/// {@macro flutter.material.inkwell.onFocusChange}
final
ValueChanged
<
bool
>?
onFocusChange
;
/// {@macro flutter.material.ListTile.enableFeedback}
///
/// See also:
...
...
@@ -394,6 +399,7 @@ class SwitchListTile extends StatelessWidget {
inactiveTrackColor:
inactiveTrackColor
,
inactiveThumbColor:
inactiveThumbColor
,
autofocus:
autofocus
,
onFocusChange:
onFocusChange
,
);
break
;
...
...
@@ -409,6 +415,7 @@ class SwitchListTile extends StatelessWidget {
inactiveTrackColor:
inactiveTrackColor
,
inactiveThumbColor:
inactiveThumbColor
,
autofocus:
autofocus
,
onFocusChange:
onFocusChange
,
);
}
...
...
@@ -452,6 +459,7 @@ class SwitchListTile extends StatelessWidget {
tileColor:
tileColor
,
visualDensity:
visualDensity
,
focusNode:
focusNode
,
onFocusChange:
onFocusChange
,
enableFeedback:
enableFeedback
,
hoverColor:
hoverColor
,
),
...
...
packages/flutter/lib/src/material/toggleable.dart
View file @
a9c2f8b9
...
...
@@ -305,6 +305,7 @@ mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin
/// build method - potentially after wrapping it in other widgets.
Widget
buildToggleable
({
FocusNode
?
focusNode
,
Function
(
bool
)?
onFocusChange
,
bool
autofocus
=
false
,
required
MaterialStateProperty
<
MouseCursor
>
mouseCursor
,
required
Size
size
,
...
...
@@ -314,6 +315,7 @@ mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin
actions:
_actionMap
,
focusNode:
focusNode
,
autofocus:
autofocus
,
onFocusChange:
onFocusChange
,
enabled:
isInteractive
,
onShowFocusHighlight:
_handleFocusHighlightChanged
,
onShowHoverHighlight:
_handleHoverChanged
,
...
...
packages/flutter/test/material/checkbox_list_tile_test.dart
View file @
a9c2f8b9
...
...
@@ -431,6 +431,35 @@ void main() {
expect
(
tileNode
.
hasPrimaryFocus
,
isTrue
);
});
testWidgets
(
'CheckboxListTile onFocusChange callback'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
node
=
FocusNode
(
debugLabel:
'CheckboxListTile onFocusChange'
);
bool
gotFocus
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
CheckboxListTile
(
value:
true
,
focusNode:
node
,
onFocusChange:
(
bool
focused
)
{
gotFocus
=
focused
;
},
onChanged:
(
bool
?
value
)
{},
),
),
),
);
node
.
requestFocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isTrue
);
expect
(
node
.
hasFocus
,
isTrue
);
node
.
unfocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isFalse
);
expect
(
node
.
hasFocus
,
isFalse
);
});
testWidgets
(
'CheckboxListTile can be disabled'
,
(
WidgetTester
tester
)
async
{
bool
?
value
=
false
;
bool
enabled
=
true
;
...
...
packages/flutter/test/material/list_tile_test.dart
View file @
a9c2f8b9
...
...
@@ -1476,6 +1476,34 @@ void main() {
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
basic
);
});
testWidgets
(
'ListTile onFocusChange callback'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
node
=
FocusNode
(
debugLabel:
'ListTile Focus'
);
bool
gotFocus
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
ListTile
(
focusNode:
node
,
onFocusChange:
(
bool
focused
)
{
gotFocus
=
focused
;
},
onTap:
()
{},
),
),
),
);
node
.
requestFocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isTrue
);
expect
(
node
.
hasFocus
,
isTrue
);
node
.
unfocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isFalse
);
expect
(
node
.
hasFocus
,
isFalse
);
});
testWidgets
(
'ListTile respects tileColor & selectedTileColor'
,
(
WidgetTester
tester
)
async
{
bool
isSelected
=
false
;
final
Color
tileColor
=
Colors
.
green
.
shade500
;
...
...
packages/flutter/test/material/radio_list_tile_test.dart
View file @
a9c2f8b9
...
...
@@ -793,6 +793,36 @@ void main() {
expect
(
tileNode
.
hasPrimaryFocus
,
isTrue
);
});
testWidgets
(
'RadioListTile onFocusChange callback'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
node
=
FocusNode
(
debugLabel:
'RadioListTile onFocusChange'
);
bool
gotFocus
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
RadioListTile
<
bool
>(
value:
true
,
focusNode:
node
,
onFocusChange:
(
bool
focused
)
{
gotFocus
=
focused
;
},
onChanged:
(
bool
?
value
)
{},
groupValue:
true
,
),
),
),
);
node
.
requestFocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isTrue
);
expect
(
node
.
hasFocus
,
isTrue
);
node
.
unfocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isFalse
);
expect
(
node
.
hasFocus
,
isFalse
);
});
group
(
'feedback'
,
()
{
late
FeedbackTester
feedback
;
...
...
packages/flutter/test/material/switch_list_tile_test.dart
View file @
a9c2f8b9
...
...
@@ -480,6 +480,64 @@ void main() {
expect
(
tileNode
.
hasPrimaryFocus
,
isTrue
);
});
testWidgets
(
'SwitchListTile onFocusChange callback'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
node
=
FocusNode
(
debugLabel:
'SwitchListTile onFocusChange'
);
bool
gotFocus
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
SwitchListTile
(
value:
true
,
focusNode:
node
,
onFocusChange:
(
bool
focused
)
{
gotFocus
=
focused
;
},
onChanged:
(
bool
value
)
{},
),
),
),
);
node
.
requestFocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isTrue
);
expect
(
node
.
hasFocus
,
isTrue
);
node
.
unfocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isFalse
);
expect
(
node
.
hasFocus
,
isFalse
);
});
testWidgets
(
'SwitchListTile.adaptive onFocusChange Callback'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
node
=
FocusNode
(
debugLabel:
'SwitchListTile.adaptive onFocusChange'
);
bool
gotFocus
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
SwitchListTile
.
adaptive
(
value:
true
,
focusNode:
node
,
onFocusChange:
(
bool
focused
)
{
gotFocus
=
focused
;
},
onChanged:
(
bool
value
)
{},
),
),
),
);
node
.
requestFocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isTrue
);
expect
(
node
.
hasFocus
,
isTrue
);
node
.
unfocus
();
await
tester
.
pump
();
expect
(
gotFocus
,
isFalse
);
expect
(
node
.
hasFocus
,
isFalse
);
});
group
(
'feedback'
,
()
{
late
FeedbackTester
feedback
;
...
...
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