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
0afea99b
Unverified
Commit
0afea99b
authored
Nov 05, 2020
by
Chinmoy
Committed by
GitHub
Nov 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added enableFeedback property to ListTile (#69088)
parent
ef4ec09a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
1 deletion
+146
-1
list_tile.dart
packages/flutter/lib/src/material/list_tile.dart
+24
-1
list_tile_test.dart
packages/flutter/test/material/list_tile_test.dart
+122
-0
No files found.
packages/flutter/lib/src/material/list_tile.dart
View file @
0afea99b
...
...
@@ -52,6 +52,7 @@ class ListTileTheme extends InheritedTheme {
this
.
contentPadding
,
this
.
tileColor
,
this
.
selectedTileColor
,
this
.
enableFeedback
,
required
Widget
child
,
})
:
super
(
key:
key
,
child:
child
);
...
...
@@ -70,6 +71,7 @@ class ListTileTheme extends InheritedTheme {
EdgeInsetsGeometry
?
contentPadding
,
Color
?
tileColor
,
Color
?
selectedTileColor
,
bool
?
enableFeedback
,
required
Widget
child
,
})
{
assert
(
child
!=
null
);
...
...
@@ -87,6 +89,7 @@ class ListTileTheme extends InheritedTheme {
contentPadding:
contentPadding
??
parent
.
contentPadding
,
tileColor:
tileColor
??
parent
.
tileColor
,
selectedTileColor:
selectedTileColor
??
parent
.
selectedTileColor
,
enableFeedback:
enableFeedback
??
parent
.
enableFeedback
,
child:
child
,
);
},
...
...
@@ -131,6 +134,11 @@ class ListTileTheme extends InheritedTheme {
/// If [ListTile.selectedTileColor] is provided, [selectedTileColor] is ignored.
final
Color
?
selectedTileColor
;
/// If specified, defines the feedback property for `ListTile`.
///
/// If [ListTile.enableFeedback] is provided, [enableFeedback] is ignored.
final
bool
?
enableFeedback
;
/// The closest instance of this class that encloses the given context.
///
/// Typical usage is as follows:
...
...
@@ -155,6 +163,7 @@ class ListTileTheme extends InheritedTheme {
contentPadding:
contentPadding
,
tileColor:
tileColor
,
selectedTileColor:
selectedTileColor
,
enableFeedback:
enableFeedback
,
child:
child
,
);
}
...
...
@@ -169,7 +178,8 @@ class ListTileTheme extends InheritedTheme {
||
textColor
!=
oldWidget
.
textColor
||
contentPadding
!=
oldWidget
.
contentPadding
||
tileColor
!=
oldWidget
.
tileColor
||
selectedTileColor
!=
oldWidget
.
selectedTileColor
;
||
selectedTileColor
!=
oldWidget
.
selectedTileColor
||
enableFeedback
!=
oldWidget
.
enableFeedback
;
}
}
...
...
@@ -708,6 +718,7 @@ class ListTile extends StatelessWidget {
this
.
autofocus
=
false
,
this
.
tileColor
,
this
.
selectedTileColor
,
this
.
enableFeedback
,
})
:
assert
(
isThreeLine
!=
null
),
assert
(
enabled
!=
null
),
assert
(
selected
!=
null
),
...
...
@@ -901,6 +912,16 @@ class ListTile extends StatelessWidget {
/// if it's not null and to [Colors.transparent] if it's null.
final
Color
?
selectedTileColor
;
/// Whether detected gestures should provide acoustic and/or haptic feedback.
///
/// For example, on Android a tap will produce a clicking sound and a
/// long-press will produce a short vibration, when feedback is enabled.
///
/// See also:
///
/// * [Feedback] for providing platform-specific feedback to certain actions.
final
bool
?
enableFeedback
;
/// Add a one pixel border in between each tile. If color isn't specified the
/// [ThemeData.dividerColor] of the context's [Theme] is used.
///
...
...
@@ -1068,6 +1089,7 @@ class ListTile extends StatelessWidget {
const
EdgeInsets
_defaultContentPadding
=
EdgeInsets
.
symmetric
(
horizontal:
16.0
);
final
TextDirection
textDirection
=
Directionality
.
of
(
context
);
final
bool
resolvedEnableFeedback
=
enableFeedback
??
tileTheme
.
enableFeedback
??
true
;
final
EdgeInsets
resolvedContentPadding
=
contentPadding
?.
resolve
(
textDirection
)
??
tileTheme
.
contentPadding
?.
resolve
(
textDirection
)
??
_defaultContentPadding
;
...
...
@@ -1090,6 +1112,7 @@ class ListTile extends StatelessWidget {
focusColor:
focusColor
,
hoverColor:
hoverColor
,
autofocus:
autofocus
,
enableFeedback:
resolvedEnableFeedback
,
child:
Semantics
(
selected:
selected
,
enabled:
enabled
,
...
...
packages/flutter/test/material/list_tile_test.dart
View file @
0afea99b
...
...
@@ -13,6 +13,7 @@ import 'package:flutter_test/flutter_test.dart';
import
'../rendering/mock_canvas.dart'
;
import
'../widgets/semantics_tester.dart'
;
import
'feedback_tester.dart'
;
class
TestIcon
extends
StatefulWidget
{
const
TestIcon
({
Key
?
key
})
:
super
(
key:
key
);
...
...
@@ -1712,4 +1713,125 @@ void main() {
expect
(
renderBox
.
size
.
width
,
equals
(
0.0
));
expect
(
renderBox
.
size
.
height
,
equals
(
0.0
));
});
group
(
'feedback'
,
()
{
late
FeedbackTester
feedback
;
setUp
(()
{
feedback
=
FeedbackTester
();
});
tearDown
(()
{
feedback
.
dispose
();
});
testWidgets
(
'ListTile with disabled feedback'
,
(
WidgetTester
tester
)
async
{
const
bool
enableFeedback
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
ListTile
(
title:
const
Text
(
'Title'
),
onTap:
()
{},
enableFeedback:
enableFeedback
,
),
),
),
);
await
tester
.
tap
(
find
.
byType
(
ListTile
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
feedback
.
clickSoundCount
,
0
);
expect
(
feedback
.
hapticCount
,
0
);
});
testWidgets
(
'ListTile with enabled feedback'
,
(
WidgetTester
tester
)
async
{
const
bool
enableFeedback
=
true
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
ListTile
(
title:
const
Text
(
'Title'
),
onTap:
()
{},
enableFeedback:
enableFeedback
,
),
),
),
);
await
tester
.
tap
(
find
.
byType
(
ListTile
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
feedback
.
clickSoundCount
,
1
);
expect
(
feedback
.
hapticCount
,
0
);
});
testWidgets
(
'ListTile with enabled feedback by default'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
ListTile
(
title:
const
Text
(
'Title'
),
onTap:
()
{},
),
),
),
);
await
tester
.
tap
(
find
.
byType
(
ListTile
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
feedback
.
clickSoundCount
,
1
);
expect
(
feedback
.
hapticCount
,
0
);
});
testWidgets
(
'ListTile with disabled feedback using ListTileTheme'
,
(
WidgetTester
tester
)
async
{
const
bool
enableFeedbackTheme
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
ListTileTheme
(
enableFeedback:
enableFeedbackTheme
,
child:
ListTile
(
title:
const
Text
(
'Title'
),
onTap:
()
{},
),
),
),
),
);
await
tester
.
tap
(
find
.
byType
(
ListTile
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
feedback
.
clickSoundCount
,
0
);
expect
(
feedback
.
hapticCount
,
0
);
});
testWidgets
(
'ListTile.enableFeedback overrides ListTileTheme.enableFeedback'
,
(
WidgetTester
tester
)
async
{
const
bool
enableFeedbackTheme
=
false
;
const
bool
enableFeedback
=
true
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
ListTileTheme
(
enableFeedback:
enableFeedbackTheme
,
child:
ListTile
(
enableFeedback:
enableFeedback
,
title:
const
Text
(
'Title'
),
onTap:
()
{},
),
),
),
),
);
await
tester
.
tap
(
find
.
byType
(
ListTile
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
feedback
.
clickSoundCount
,
1
);
expect
(
feedback
.
hapticCount
,
0
);
});
});
}
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