Widgets

/

interact

Toggle

A checkbox or switch.

Also written Checkbox, Switch; layr format rewrites these to Toggle.

A checkbox or a switch

Toggle is a labelled on/off control: kind: checkbox (the default) or kind: switch. .fnc { … } runs with the new value.

LAYROpen in playground
Page(
  .name(Settings)
  .route('/')
  var bool notify = true
  Scaffold(
    .config(color: canvas)
    .body(
      Column(
        .config(gap: 14, padding: all(24))
        Toggle(
          .config(
            kind: switch
            label: 'Email me when a room frees up'
            value: notify
          )
          .fnc { notify = value }
        )
        Text(
          .config(color: muted)
          .obj(notify ? 'You will get an email.' : 'No emails.')
        )
      )
    )
  )
)

Config keys

KeyTypeDefaultMeaning
valueboolOn or off.
labeltxtLabel.
kindcheckbox | switchcheckboxPresentation.
disabledboolDisabled.
margininsetsSpace outside the object: all(8), sym(x: 8, y: 4), only(top: 8).
opacitynumOpacity from 0 to 1.
hide (hidden)boolRemoves the object from layout and the accessibility tree.
shrinknum1Shrink priority when space runs out. Lower shrinks first; 0 never shrinks.
flexnum1Share of remaining space for fill sizes.
cursorauto | pointer | text | grab | grabbing | move | notAllowed | crosshair | nonePointer cursor.
className (class)txtExtra CSS class names: styling hooks for your own stylesheet (hover rules, third-party CSS).

Events

.fnc runs on change. .on(...) accepts tap, press, hover, hoverEnd, focus, blur, key, drag, swipe, mount, unmount, visible.