Code Monkey home page Code Monkey logo

Comments (10)

letsar avatar letsar commented on May 26, 2024 5

Oh thanks, I understand ๐Ÿ˜ƒ .

To do this, you need to pass a SlidableController to all your Slidables. Then you can call the close method on the SlidableController.activeState property inside the onTap callback of a GestureDetector.

I suggest you to create a Widget for this:

class CloseSlidableOnTap extends StatelessWidget {
  CloseSlidableOnTap({
    Key key,
    this.child,
    this.controller,
  }) : super(key: key);

  final Widget child;
  final SlidableController controller;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () => controller.activeState?.close(),
      child: child,
    );
  }
}

from flutter_slidable.

minhtamkv avatar minhtamkv commented on May 26, 2024 2

How can I pass a SlidableController to all my Slidable. Slidable isn't have controller property. @letsar

from flutter_slidable.

zywj avatar zywj commented on May 26, 2024 1

oh thanks very much!

from flutter_slidable.

letsar avatar letsar commented on May 26, 2024

Hi @zywj, can post the minimal code to reproduce this issue please?

from flutter_slidable.

zywj avatar zywj commented on May 26, 2024

thanks for you reply. I just don't know how to hide the slidable when I tap other areas on the screen, not just the slidable item area.

from flutter_slidable.

letsar avatar letsar commented on May 26, 2024

I'm sorry, can you post an image or a video showing what you want? I'm not sure to understand.

from flutter_slidable.

zywj avatar zywj commented on May 26, 2024

sorry. I didn't describe my needs very clear.
I want to close the slidable when I tap the any other areas on the screen.
let me show you a image.

b39706f7-9061-40ab-b7e1-7afb81b9d0ec

from flutter_slidable.

minhdanh avatar minhdanh commented on May 26, 2024

@letsar Hi, is there a way we can close a slidable automatically when any of its outside area is tapped?

from flutter_slidable.

Rongix avatar Rongix commented on May 26, 2024

@minhdanh
In slidable: wrap child with builder then use gesture detector to handle on tap -> (in on Tap send notification to close slidable, it is marked as internal use but it works if you need it asap)

GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () {
          Slidable.of(context)!.close();
          SlidableGroupNotification.dispatch(
            context,
            SlidableAutoCloseNotification(
              groupTag: '0',
              controller: Slidable.of(context)!,
            ),
            assertParentExists: false,
          );
        },
        child: Container(

Tho this is only useful if you want to close slidables when clicking on another slidable (not anywhere on the screen)

from flutter_slidable.

minhdanh avatar minhdanh commented on May 26, 2024

Thank you @Rongix

from flutter_slidable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.