victorevox / simple_tooltp

MIT License
30 stars 47 forks source link

Show tooltip on demand #15

Closed MoeHamdan closed 4 years ago

MoeHamdan commented 4 years ago

Hello

How can I show the tooltip when I tap on the child?

victorevox commented 4 years ago

Hi @MoeHamdan,

You should be able to do that by handling the tap on the child by GestureDetector and then updating the state to change the show property, here a quick example


class ExampleContainer extends StatefulWidget {
  ExampleContainer({Key key}) : super(key: key);

  @override
  _ExampleContainerState createState() => _ExampleContainerState();
}

class _ExampleContainerState extends State<ExampleContainer> {
  bool _sholdShow = false;
  @override
  Widget build(BuildContext context) {
    return SimpleTooltip(
      show: _sholdShow,
      content: Text("content"),
      child: GestureDetector(
        onTap: () {
          setState(() {
            _sholdShow = true;
          });
        },
        child: Container(),
      ),
    );
  }
}

Hope it helps