I want to show a tooltip on a single tap, not a long tap.
Can anyone help me with this?
Tooltip(
message: e.title,
child: Card(
semanticContainer: true,
child: Padding(
padding: EdgeInsets.symmetric(
vertical: 12,
horizontal: 12
),
child: Center(
child: Image.network(
e.icon,
height: 40,
),
),
),
),
)
You can wrap your text into a Tooltip widget. Show activity on this post. Tooltip(message: "This is the tooltip message", child: new Text("Show tooltip")); You can also provide a height, decoration and other parameters.
SuperTooltip is derived from a widget I wrote for a client. It is super flexible and allows you to display ToolTips in the overlay of the screen. The whole screen gets covered with a typically translucent background color. Tapping on the background closes the Tooltip.
The easiest way would be to view the source code, copy it over to your project, change the direct references from import colors. dart'; to import 'package:flutter/src/material/colors. dart'; and then make the necessary change you want.
The easiest way to do it is to use triggerMode
property inside Tooltip constructor.
Tooltip(
message: item.description ?? '',
triggerMode: TooltipTriggerMode.tap,
child: Text(item.label ?? '',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 1.7.t.toDouble(),
color: Colors.black.withOpacity(0.6),
)),
)
UPDATE:
use triggerMode: TooltipTriggerMode.tap,
instead
THIS SOLUTION IS OBSOLETE
as an option you can create simple wrapper widget
full example:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: Home());
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Home")),
body: Center(
child: MyTooltip(
message: 'message',
child: Image.network('https://picsum.photos/seed/picsum/200/300', height: 40),
),
),
);
}
}
class MyTooltip extends StatelessWidget {
final Widget child;
final String message;
MyTooltip({@required this.message, @required this.child});
@override
Widget build(BuildContext context) {
final key = GlobalKey<State<Tooltip>>();
return Tooltip(
key: key,
message: message,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => _onTap(key),
child: child,
),
);
}
void _onTap(GlobalKey key) {
final dynamic tooltip = key.currentState;
tooltip?.ensureTooltipVisible();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With