Add useDeleteButtonTooltip property for Chip (#68237)
This commit is contained in:
parent
7b86be228e
commit
f03caeafa7
1
AUTHORS
1
AUTHORS
@ -69,3 +69,4 @@ Terrence Addison Tandijono(flotilla) <terrenceaddison32@gmail.com>
|
||||
YeungKC <flutter@yeungkc.com>
|
||||
Nobuhiro Tabuki <japanese.around30@gmail.com>
|
||||
nt4f04uNd <nt4f04und@gmail.com>
|
||||
Anurag Roy <anuragr9847@gmail.com>
|
||||
|
@ -258,7 +258,15 @@ abstract class DeletableChipAttributes {
|
||||
/// [IconThemeData.color].
|
||||
Color? get deleteIconColor;
|
||||
|
||||
/// Whether to use a tooltip on the chip's delete button showing the
|
||||
/// [deleteButtonTooltipMessage].
|
||||
///
|
||||
/// Must not be null. Defaults to true.
|
||||
bool get useDeleteButtonTooltip;
|
||||
|
||||
/// The message to be used for the chip's delete button tooltip.
|
||||
///
|
||||
/// This will be shown only if [useDeleteButtonTooltip] is true.
|
||||
String? get deleteButtonTooltipMessage;
|
||||
}
|
||||
|
||||
@ -566,6 +574,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
|
||||
this.deleteIcon,
|
||||
this.onDeleted,
|
||||
this.deleteIconColor,
|
||||
this.useDeleteButtonTooltip = true,
|
||||
this.deleteButtonTooltipMessage,
|
||||
this.shape,
|
||||
this.clipBehavior = Clip.none,
|
||||
@ -581,6 +590,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
|
||||
assert(autofocus != null),
|
||||
assert(clipBehavior != null),
|
||||
assert(elevation == null || elevation >= 0.0),
|
||||
assert(useDeleteButtonTooltip != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
@ -612,6 +622,8 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
|
||||
@override
|
||||
final Color? deleteIconColor;
|
||||
@override
|
||||
final bool useDeleteButtonTooltip;
|
||||
@override
|
||||
final String? deleteButtonTooltipMessage;
|
||||
@override
|
||||
final MaterialTapTargetSize? materialTapTargetSize;
|
||||
@ -631,6 +643,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
|
||||
deleteIcon: deleteIcon,
|
||||
onDeleted: onDeleted,
|
||||
deleteIconColor: deleteIconColor,
|
||||
useDeleteButtonTooltip: useDeleteButtonTooltip,
|
||||
deleteButtonTooltipMessage: deleteButtonTooltipMessage,
|
||||
tapEnabled: false,
|
||||
shape: shape,
|
||||
@ -722,6 +735,7 @@ class InputChip extends StatelessWidget
|
||||
this.deleteIcon,
|
||||
this.onDeleted,
|
||||
this.deleteIconColor,
|
||||
this.useDeleteButtonTooltip = true,
|
||||
this.deleteButtonTooltipMessage,
|
||||
this.onPressed,
|
||||
this.pressElevation,
|
||||
@ -749,6 +763,7 @@ class InputChip extends StatelessWidget
|
||||
assert(autofocus != null),
|
||||
assert(pressElevation == null || pressElevation >= 0.0),
|
||||
assert(elevation == null || elevation >= 0.0),
|
||||
assert(useDeleteButtonTooltip != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
@ -772,6 +787,8 @@ class InputChip extends StatelessWidget
|
||||
@override
|
||||
final Color? deleteIconColor;
|
||||
@override
|
||||
final bool useDeleteButtonTooltip;
|
||||
@override
|
||||
final String? deleteButtonTooltipMessage;
|
||||
@override
|
||||
final VoidCallback? onPressed;
|
||||
@ -823,6 +840,7 @@ class InputChip extends StatelessWidget
|
||||
deleteIcon: deleteIcon,
|
||||
onDeleted: onDeleted,
|
||||
deleteIconColor: deleteIconColor,
|
||||
useDeleteButtonTooltip: useDeleteButtonTooltip,
|
||||
deleteButtonTooltipMessage: deleteButtonTooltipMessage,
|
||||
onSelected: onSelected,
|
||||
onPressed: onPressed,
|
||||
@ -1448,6 +1466,7 @@ class RawChip extends StatefulWidget
|
||||
Widget? deleteIcon,
|
||||
this.onDeleted,
|
||||
this.deleteIconColor,
|
||||
this.useDeleteButtonTooltip = true,
|
||||
this.deleteButtonTooltipMessage,
|
||||
this.onPressed,
|
||||
this.onSelected,
|
||||
@ -1477,6 +1496,7 @@ class RawChip extends StatefulWidget
|
||||
assert(autofocus != null),
|
||||
assert(pressElevation == null || pressElevation >= 0.0),
|
||||
assert(elevation == null || elevation >= 0.0),
|
||||
assert(useDeleteButtonTooltip != null),
|
||||
deleteIcon = deleteIcon ?? _kDefaultDeleteIcon,
|
||||
super(key: key);
|
||||
|
||||
@ -1495,6 +1515,8 @@ class RawChip extends StatefulWidget
|
||||
@override
|
||||
final Color? deleteIconColor;
|
||||
@override
|
||||
final bool useDeleteButtonTooltip;
|
||||
@override
|
||||
final String? deleteButtonTooltipMessage;
|
||||
@override
|
||||
final ValueChanged<bool>? onSelected;
|
||||
@ -1767,6 +1789,9 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
|
||||
}
|
||||
|
||||
Widget? _wrapWithTooltip(String? tooltip, VoidCallback? callback, Widget? child) {
|
||||
if(!widget.useDeleteButtonTooltip){
|
||||
return child;
|
||||
}
|
||||
if (child == null || callback == null || tooltip == null) {
|
||||
return child;
|
||||
}
|
||||
|
@ -193,6 +193,7 @@ Widget _chipWithOptionalDeleteButton({
|
||||
UniqueKey? labelKey,
|
||||
required bool deletable,
|
||||
TextDirection textDirection = TextDirection.ltr,
|
||||
bool hasDeleteButtonTooltip = true,
|
||||
}){
|
||||
return _wrapForChip(
|
||||
textDirection: textDirection,
|
||||
@ -202,6 +203,7 @@ Widget _chipWithOptionalDeleteButton({
|
||||
onPressed: () {},
|
||||
onDeleted: deletable ? () {} : null,
|
||||
deleteIcon: Icon(Icons.close, key: deleteButtonKey),
|
||||
useDeleteButtonTooltip: hasDeleteButtonTooltip,
|
||||
label: Text(
|
||||
deletable
|
||||
? 'Chip with Delete Button'
|
||||
@ -2679,4 +2681,29 @@ void main() {
|
||||
const Color(0xffff0000),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Chip delete button tooltip can be disabled', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
_chipWithOptionalDeleteButton(
|
||||
deletable: true,
|
||||
hasDeleteButtonTooltip: false,
|
||||
)
|
||||
);
|
||||
|
||||
// Tap at the delete icon of the chip, which is at the right
|
||||
// side of the chip
|
||||
final Offset topRightOfInkwell = tester.getTopLeft(find.byType(InkWell));
|
||||
final Offset tapLocationOfDeleteButton = topRightOfInkwell + const Offset(8, 8);
|
||||
final TestGesture tapGesture = await tester.startGesture(tapLocationOfDeleteButton);
|
||||
|
||||
await tester.pump();
|
||||
|
||||
// Wait for some more time while pressing and holding the delete button
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// There should be no tooltip
|
||||
expect(findTooltipContainer('Delete'), findsNothing);
|
||||
|
||||
await tapGesture.up();
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user