Ask the assistant
0/400
Your question is processed by an AI service and kept to improve answers. Do not enter personal data.

    InkWell

    Makes any element tappable: catches a tap, a double tap and a long press and shows feedback — a ripple in the app, a highlight on hover and press on the site. It is the most common way to make an arbitrary block "clickable" — a card, a list row, an icon.

    Type: single-child

    @taps:0
    InkWell onTap:{taps = taps + 1}
      Padding
        #padding all 16
        Text "Tap me"

    Parameters

    Parameter Type Description
    onTap callback Tap
    onDoubleTap callback Double tap (app only)
    onLongPress callback Long press (app only)
    splashColor color Ripple color (on the site — the highlight color on press)
    highlightColor color Highlight color on press
    hoverColor color Highlight color on mouse hover
    focusColor color Highlight color on keyboard focus

    A handler is written in any of three forms, as with Button :

    • a body {…} — runs on tap (for example, onTap:{opened = !opened} );
    • an action string "navigate:/home" — an app action is invoked;
    • a variable holding a function, onTap:$copy .

    An element without a handler promises nothing: on the site it gets neither the hand cursor nor a highlight.

    Nested structures

    #borderRadius and #customBorder

    The shape the ripple is clipped to (in the app). For rounding — #borderRadius circular 12 , for an arbitrary shape — #customBorder (same format as the #shape of buttons).

    @opened:false
    InkWell onTap:{opened = !opened}
      #borderRadius circular 12
      Padding
        #padding all 16
        Text "With a rounded ripple"

    Examples

    Clickable card

    @selected:false
    InkWell onTap:{selected = !selected} hoverColor:#1A36345E
      DecoratedBox
        #decoration color:#36345E
          #borderRadius circular 16
        Padding
          #padding all 20
          Column spacing:4 crossAxisAlignment:start
            Text "Basic plan"
            Text "Tap to choose"
    InkWell onTap:"navigate:/pricing"
      Padding
        #padding symmetric horizontal:12 vertical:8
        Text "Pricing"

    Differences between the app and the site

    • In the app the feedback is a ripple from the tap point on the nearest Material layer. An opaque fill of the child ( ColoredBox , DecoratedBox with a color) lies above the ripple and hides it; if you need a visible ripple, do not paint the whole child.
    • On the site there is a ripple from the tap point and a highlight layer on hover and press. The cursor becomes a hand only if there is a handler.
    • From the keyboard it works as in the app: an InkWell with a handler is reached with Tab, activated with Enter and Space (without modifiers), and on keyboard focus is highlighted with focusColor (12 % black by default). A screen reader announces it as a button — so an InkWell with only an icon inside needs a name: Semantics label:"Menu" around it.
    • It is not always called a button. A navigation ( navigator.show , navigate: ) becomes a real <a href> link. A card that has its own buttons or links inside gets focus and keys, but not the button role: a button inside a button is an accessibility error. That is why the name goes on the InkWell itself — Semantics label: around it — and not #web role:button ariaLabel: on a block inside: the block is not what gets focus. A ListView / GridView row stays a list item. A role named by the author ( Semantics link:true , #web role: ) wins.
    • onDoubleTap , onLongPress , #borderRadius and #customBorder are not read on the site. An InkWell without a child is an empty block on the site.

    Bad practices

    A tappable element without a handler

    // BAD — InkWell without onTap: looks tappable only in the app, and only through the ripple
    InkWell
      Text "Tap"
    // GOOD — there is a handler, the feedback is honest
    @clicked:false
    InkWell onTap:{clicked = true}
      Text "Tap"

    See also

    • Button — a button built on InkWell , with onHover / onExit
    • Padding — the tappable area is usually set with padding inside the InkWell