简体   繁体   中英

How can I listen Tap Event outside a container in Flutter?

每当我在容器外轻敲时,我都试图让容器消失

"

Use Visibility widget and put your containers into a stack

bool isVisible = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: stackedContainers()
    );
  }

  Stack stackedContainers() {
    return new Stack(
      children: <Widget>[
        myContainer(),
        GestureDetector(
          child: background(),
          onTap: () {
            setState(() {
              isVisible = false;
            });
          },
        )
      ],
    );
  }

  Container myContainer() {
    return Container(
      child: Visibility(
        visible: isVisible,
       //.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM