光标位于按钮上时如何在网页中添加意见箱
How to add suggetionbox in web when cursor is on button
我想在 flutter web 中当光标在按钮上或某个小部件上时显示建议
我分享了我想如何显示建议框的示例,但我不知道如何在 flutter 中添加建议框
您需要使用工具提示包装小部件,请参见示例。
用工具提示包裹小部件
super_tooltip: ^1.0.1
https://pub.dev/packages/super_tooltip
class TargetWidget extends StatefulWidget {
const TargetWidget({Key? key}) : super(key: key);
@override
_TargetWidgetState createState() => new _TargetWidgetState();
}
class _TargetWidgetState extends State<TargetWidget> {
SuperTooltip? tooltip;
Future<bool> _willPopCallback() async {
// If the tooltip is open we don't pop the page on a backbutton press
// but close the ToolTip
if (tooltip!.isOpen) {
tooltip!.close();
return false;
}
return true;
}
void onTap() {
if (tooltip != null && tooltip!.isOpen) {
tooltip!.close();
return;
}
var renderBox = context.findRenderObject() as RenderBox;
final overlay = Overlay.of(context)!.context.findRenderObject() as RenderBox?;
var targetGlobalCenter = renderBox
.localToGlobal(renderBox.size.center(Offset.zero), ancestor: overlay);
// We create the tooltip on the first use
tooltip = SuperTooltip(
popupDirection: TooltipDirection.left,
arrowTipDistance: 15.0,
arrowBaseWidth: 40.0,
arrowLength: 40.0,
borderColor: Colors.green,
borderWidth: 5.0,
snapsFarAwayVertically: true,
showCloseButton: ShowCloseButton.inside,
hasShadow: false,
touchThrougArea: new Rect.fromLTWH(targetGlobalCenter.dx - 100,
targetGlobalCenter.dy - 100, 200.0, 160.0),
touchThroughAreaShape: ClipAreaShape.rectangle,
content: new Material(
child: Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
"sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, "
"sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. ",
softWrap: true,
),
)),
);
tooltip!.show(context);
}
@override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: _willPopCallback,
child: new GestureDetector(
onTap: onTap,
child: Container(
width: 20.0,
height: 20.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Colors.blue,
)),
),
);
}
}
试试下面的代码希望对你有帮助。使用 Tooltip
小部件
参考Tooltip
here
测试下面的代码here
Tooltip(
message: "Managers",
child: ElevatedButton(
onPressed: () {},
child: Text('OK'),
),
),
结果屏幕->
除了所有与工具提示相关的建议,如果它们不能完全满足您的要求,还有 OverlayEntry 它允许使用任何小部件,但不是很容易处理,所以有几个包您可能会考虑使用叠加层为您做一些工作。
https://pub.dev/packages/flutter_portal
https://pub.dev/packages/modals
要在将鼠标悬停在某个小部件上时显示覆盖条目,请用 MouseRegion 包裹它并使用其 onEnter
和 onExit
方法来显示和隐藏覆盖
我想在 flutter web 中当光标在按钮上或某个小部件上时显示建议
我分享了我想如何显示建议框的示例,但我不知道如何在 flutter 中添加建议框
您需要使用工具提示包装小部件,请参见示例。
用工具提示包裹小部件
super_tooltip: ^1.0.1
https://pub.dev/packages/super_tooltip
class TargetWidget extends StatefulWidget {
const TargetWidget({Key? key}) : super(key: key);
@override
_TargetWidgetState createState() => new _TargetWidgetState();
}
class _TargetWidgetState extends State<TargetWidget> {
SuperTooltip? tooltip;
Future<bool> _willPopCallback() async {
// If the tooltip is open we don't pop the page on a backbutton press
// but close the ToolTip
if (tooltip!.isOpen) {
tooltip!.close();
return false;
}
return true;
}
void onTap() {
if (tooltip != null && tooltip!.isOpen) {
tooltip!.close();
return;
}
var renderBox = context.findRenderObject() as RenderBox;
final overlay = Overlay.of(context)!.context.findRenderObject() as RenderBox?;
var targetGlobalCenter = renderBox
.localToGlobal(renderBox.size.center(Offset.zero), ancestor: overlay);
// We create the tooltip on the first use
tooltip = SuperTooltip(
popupDirection: TooltipDirection.left,
arrowTipDistance: 15.0,
arrowBaseWidth: 40.0,
arrowLength: 40.0,
borderColor: Colors.green,
borderWidth: 5.0,
snapsFarAwayVertically: true,
showCloseButton: ShowCloseButton.inside,
hasShadow: false,
touchThrougArea: new Rect.fromLTWH(targetGlobalCenter.dx - 100,
targetGlobalCenter.dy - 100, 200.0, 160.0),
touchThroughAreaShape: ClipAreaShape.rectangle,
content: new Material(
child: Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
"sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, "
"sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. ",
softWrap: true,
),
)),
);
tooltip!.show(context);
}
@override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: _willPopCallback,
child: new GestureDetector(
onTap: onTap,
child: Container(
width: 20.0,
height: 20.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Colors.blue,
)),
),
);
}
}
试试下面的代码希望对你有帮助。使用 Tooltip
小部件
参考Tooltip
here
测试下面的代码here
Tooltip(
message: "Managers",
child: ElevatedButton(
onPressed: () {},
child: Text('OK'),
),
),
结果屏幕->
除了所有与工具提示相关的建议,如果它们不能完全满足您的要求,还有 OverlayEntry 它允许使用任何小部件,但不是很容易处理,所以有几个包您可能会考虑使用叠加层为您做一些工作。
https://pub.dev/packages/flutter_portal
https://pub.dev/packages/modals
要在将鼠标悬停在某个小部件上时显示覆盖条目,请用 MouseRegion 包裹它并使用其 onEnter
和 onExit
方法来显示和隐藏覆盖