在目标widget上面或下面的一个提示
构造方法
长按某一widget进行提示,那么就让该widget成为ToolTip的child
const Tooltip({
Key key,
@required this.message,// 提示的内容
this.height = _defaultTooltipHeight,//提示框的高度
this.padding = _defaultPadding,// 内边距
this.verticalOffset = _defaultVerticalOffset,// 距离child的高度,上或下
this.preferBelow = true,// false 在child上面 true 在child下面提示
this.excludeFromSemantics = false,
this.decoration,// 可以对背景进行修饰
this.waitDuration = _defaultWaitDuration,// 长按的时间
this.showDuration = _defaultShowDuration,// 提示框显示的持续时间
this.child,
})
示例
代码
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Tooltip(
message: "长按提示",
child: Icon(
Icons.add_alarm,
size: 50.0,
color: Colors.blue,
),
height: 50,// 提示框的高度
padding: EdgeInsets.only(left: 10,right: 10),// 内边距
verticalOffset: 50,// 距离child的垂直距离
preferBelow: false,// false 在child上面 true 在child下面
decoration: BoxDecoration(color: Colors.black45),// 修饰
waitDuration: Duration(seconds: 2),// 长按的时间
showDuration: Duration(seconds: 5),// 显示的时间
),
],
),
),
);
}
}