一键抖动工具提示 [英] Flutter Tooltip on One Tap
本文介绍了一键抖动工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在单击而不是长按时显示工具提示.
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,
),
),
),
),
)
推荐答案
作为一个选项,您可以创建简单的包装小部件
完整示例:
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();
}
}
这篇关于一键抖动工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文