Unverified Commit f03caeaf authored by Anurag Roy's avatar Anurag Roy Committed by GitHub

Add useDeleteButtonTooltip property for Chip (#68237)

parent 7b86be22
...@@ -69,3 +69,4 @@ Terrence Addison Tandijono(flotilla) <terrenceaddison32@gmail.com> ...@@ -69,3 +69,4 @@ Terrence Addison Tandijono(flotilla) <terrenceaddison32@gmail.com>
YeungKC <flutter@yeungkc.com> YeungKC <flutter@yeungkc.com>
Nobuhiro Tabuki <japanese.around30@gmail.com> Nobuhiro Tabuki <japanese.around30@gmail.com>
nt4f04uNd <nt4f04und@gmail.com> nt4f04uNd <nt4f04und@gmail.com>
Anurag Roy <anuragr9847@gmail.com>
...@@ -258,7 +258,15 @@ abstract class DeletableChipAttributes { ...@@ -258,7 +258,15 @@ abstract class DeletableChipAttributes {
/// [IconThemeData.color]. /// [IconThemeData.color].
Color? get deleteIconColor; 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. /// The message to be used for the chip's delete button tooltip.
///
/// This will be shown only if [useDeleteButtonTooltip] is true.
String? get deleteButtonTooltipMessage; String? get deleteButtonTooltipMessage;
} }
...@@ -566,6 +574,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri ...@@ -566,6 +574,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
this.deleteIcon, this.deleteIcon,
this.onDeleted, this.onDeleted,
this.deleteIconColor, this.deleteIconColor,
this.useDeleteButtonTooltip = true,
this.deleteButtonTooltipMessage, this.deleteButtonTooltipMessage,
this.shape, this.shape,
this.clipBehavior = Clip.none, this.clipBehavior = Clip.none,
...@@ -581,6 +590,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri ...@@ -581,6 +590,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
assert(autofocus != null), assert(autofocus != null),
assert(clipBehavior != null), assert(clipBehavior != null),
assert(elevation == null || elevation >= 0.0), assert(elevation == null || elevation >= 0.0),
assert(useDeleteButtonTooltip != null),
super(key: key); super(key: key);
@override @override
...@@ -612,6 +622,8 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri ...@@ -612,6 +622,8 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
@override @override
final Color? deleteIconColor; final Color? deleteIconColor;
@override @override
final bool useDeleteButtonTooltip;
@override
final String? deleteButtonTooltipMessage; final String? deleteButtonTooltipMessage;
@override @override
final MaterialTapTargetSize? materialTapTargetSize; final MaterialTapTargetSize? materialTapTargetSize;
...@@ -631,6 +643,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri ...@@ -631,6 +643,7 @@ class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttri
deleteIcon: deleteIcon, deleteIcon: deleteIcon,
onDeleted: onDeleted, onDeleted: onDeleted,
deleteIconColor: deleteIconColor, deleteIconColor: deleteIconColor,
useDeleteButtonTooltip: useDeleteButtonTooltip,
deleteButtonTooltipMessage: deleteButtonTooltipMessage, deleteButtonTooltipMessage: deleteButtonTooltipMessage,
tapEnabled: false, tapEnabled: false,
shape: shape, shape: shape,
...@@ -722,6 +735,7 @@ class InputChip extends StatelessWidget ...@@ -722,6 +735,7 @@ class InputChip extends StatelessWidget
this.deleteIcon, this.deleteIcon,
this.onDeleted, this.onDeleted,
this.deleteIconColor, this.deleteIconColor,
this.useDeleteButtonTooltip = true,
this.deleteButtonTooltipMessage, this.deleteButtonTooltipMessage,
this.onPressed, this.onPressed,
this.pressElevation, this.pressElevation,
...@@ -749,6 +763,7 @@ class InputChip extends StatelessWidget ...@@ -749,6 +763,7 @@ class InputChip extends StatelessWidget
assert(autofocus != null), assert(autofocus != null),
assert(pressElevation == null || pressElevation >= 0.0), assert(pressElevation == null || pressElevation >= 0.0),
assert(elevation == null || elevation >= 0.0), assert(elevation == null || elevation >= 0.0),
assert(useDeleteButtonTooltip != null),
super(key: key); super(key: key);
@override @override
...@@ -772,6 +787,8 @@ class InputChip extends StatelessWidget ...@@ -772,6 +787,8 @@ class InputChip extends StatelessWidget
@override @override
final Color? deleteIconColor; final Color? deleteIconColor;
@override @override
final bool useDeleteButtonTooltip;
@override
final String? deleteButtonTooltipMessage; final String? deleteButtonTooltipMessage;
@override @override
final VoidCallback? onPressed; final VoidCallback? onPressed;
...@@ -823,6 +840,7 @@ class InputChip extends StatelessWidget ...@@ -823,6 +840,7 @@ class InputChip extends StatelessWidget
deleteIcon: deleteIcon, deleteIcon: deleteIcon,
onDeleted: onDeleted, onDeleted: onDeleted,
deleteIconColor: deleteIconColor, deleteIconColor: deleteIconColor,
useDeleteButtonTooltip: useDeleteButtonTooltip,
deleteButtonTooltipMessage: deleteButtonTooltipMessage, deleteButtonTooltipMessage: deleteButtonTooltipMessage,
onSelected: onSelected, onSelected: onSelected,
onPressed: onPressed, onPressed: onPressed,
...@@ -1448,6 +1466,7 @@ class RawChip extends StatefulWidget ...@@ -1448,6 +1466,7 @@ class RawChip extends StatefulWidget
Widget? deleteIcon, Widget? deleteIcon,
this.onDeleted, this.onDeleted,
this.deleteIconColor, this.deleteIconColor,
this.useDeleteButtonTooltip = true,
this.deleteButtonTooltipMessage, this.deleteButtonTooltipMessage,
this.onPressed, this.onPressed,
this.onSelected, this.onSelected,
...@@ -1477,6 +1496,7 @@ class RawChip extends StatefulWidget ...@@ -1477,6 +1496,7 @@ class RawChip extends StatefulWidget
assert(autofocus != null), assert(autofocus != null),
assert(pressElevation == null || pressElevation >= 0.0), assert(pressElevation == null || pressElevation >= 0.0),
assert(elevation == null || elevation >= 0.0), assert(elevation == null || elevation >= 0.0),
assert(useDeleteButtonTooltip != null),
deleteIcon = deleteIcon ?? _kDefaultDeleteIcon, deleteIcon = deleteIcon ?? _kDefaultDeleteIcon,
super(key: key); super(key: key);
...@@ -1495,6 +1515,8 @@ class RawChip extends StatefulWidget ...@@ -1495,6 +1515,8 @@ class RawChip extends StatefulWidget
@override @override
final Color? deleteIconColor; final Color? deleteIconColor;
@override @override
final bool useDeleteButtonTooltip;
@override
final String? deleteButtonTooltipMessage; final String? deleteButtonTooltipMessage;
@override @override
final ValueChanged<bool>? onSelected; final ValueChanged<bool>? onSelected;
...@@ -1767,6 +1789,9 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip ...@@ -1767,6 +1789,9 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
} }
Widget? _wrapWithTooltip(String? tooltip, VoidCallback? callback, Widget? child) { Widget? _wrapWithTooltip(String? tooltip, VoidCallback? callback, Widget? child) {
if(!widget.useDeleteButtonTooltip){
return child;
}
if (child == null || callback == null || tooltip == null) { if (child == null || callback == null || tooltip == null) {
return child; return child;
} }
......
...@@ -193,6 +193,7 @@ Widget _chipWithOptionalDeleteButton({ ...@@ -193,6 +193,7 @@ Widget _chipWithOptionalDeleteButton({
UniqueKey? labelKey, UniqueKey? labelKey,
required bool deletable, required bool deletable,
TextDirection textDirection = TextDirection.ltr, TextDirection textDirection = TextDirection.ltr,
bool hasDeleteButtonTooltip = true,
}){ }){
return _wrapForChip( return _wrapForChip(
textDirection: textDirection, textDirection: textDirection,
...@@ -202,6 +203,7 @@ Widget _chipWithOptionalDeleteButton({ ...@@ -202,6 +203,7 @@ Widget _chipWithOptionalDeleteButton({
onPressed: () {}, onPressed: () {},
onDeleted: deletable ? () {} : null, onDeleted: deletable ? () {} : null,
deleteIcon: Icon(Icons.close, key: deleteButtonKey), deleteIcon: Icon(Icons.close, key: deleteButtonKey),
useDeleteButtonTooltip: hasDeleteButtonTooltip,
label: Text( label: Text(
deletable deletable
? 'Chip with Delete Button' ? 'Chip with Delete Button'
...@@ -2679,4 +2681,29 @@ void main() { ...@@ -2679,4 +2681,29 @@ void main() {
const Color(0xffff0000), 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();
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment