Flutter Tooltip on all widgets

后端 未结 2 1696
有刺的猬
有刺的猬 2021-02-20 10:02

Is there a way to set a tooltip on a Text widget:

new Text(
    \"Some content\",
    tooltip: \"Displays a message to you\"
  )


        
相关标签:
2条回答
  • 2021-02-20 10:39

    You can wrap your text into a Tooltip widget.

    new Tooltip(message: "Hello World", child: new Text("foo"));
    
    0 讨论(0)
  • 2021-02-20 10:51

    While Rémi's answer is correct, you can also create your own widget like this:

    class TooltipText extends StatelessWidget {
      final String text;
      final String tooltip;
    
      TooltipText({Key key, this.tooltip, this.text});
    
      @override
      Widget build(BuildContext context) {
        return Tooltip(
          message: tooltip,
          child: Text(text),
        );
      }
    }
    

    And use it like this:

    TooltipText(
        text: "Text",
        tooltip: "tiptool",
    );
    
    0 讨论(0)
提交回复
热议问题