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

    Choosing from options

    Elements a person uses to choose a value: one option out of several ( Radio , SegmentedButton ), a number from a range ( Slider ), a set of toggled buttons ( ToggleButtons ). Like Checkbox , they hold no value : they show what they were given and report the choice through a handler; the markup author writes the new value into the state.

    Which one to use: two to five mutually exclusive options that must all be visible at once — SegmentedButton or a group of Radio ; a long list — a dropdown ; a number — Slider ; a bar of independent toggles (bold / italic) — ToggleButtons ; a single yes/no — Switch or Checkbox .

    Radio

    A round button for choosing one option of a group. A group is formed by buttons with a common groupValue : the selected one is the one whose value equals groupValue . A caption next to it is a separate Text .

    Type: leaf

    @size:"m"
    Row
      Radio value:"s" groupValue:$size onChanged:(value){size = value}
      Text "S"
      Radio value:"m" groupValue:$size onChanged:(value){size = value}
      Text "M"
    Parameter Type Default Description
    value any — This button's value
    groupValue any — The group's selected value. The button is selected when value equals it
    onChanged callback — Called on tap; the value argument is the tapped button's value: (value){…} (with toggleable — an empty value when the selection is cleared). Without it the button is disabled
    toggleable bool false Tapping the selected button again clears the selection
    activeColor color — Color of the selected button
    focusColor color — Highlight color on focus (app only)
    hoverColor color — Highlight color on hover (app only)
    #visualDensity VisualDensity — Density: standard , comfortable , compact , adaptivePlatformDensity

    Slider

    A slider for choosing a number in the range min … max . With divisions the value moves in steps, and while dragging, label is shown above the thumb.

    Type: leaf

    @volume:0.5
    Slider value:$volume onChanged:(value){volume = value}
    Parameter Type Default Description
    value double 0 Current value. Must lie within min … max
    onChanged callback — Called while dragging, receives the new value in value : (value){…} . Without it the slider is disabled
    min double 0 Smallest value
    max double 1 Largest value
    divisions int — Number of steps between min and max . Without it the value is continuous
    label string — Caption above the thumb while dragging; shown only together with divisions (app only)
    activeColor color — Color of the covered part of the track
    inactiveColor color — Color of the remaining part of the track
    thumbColor color — Thumb color
    secondaryTrackValue double — A second value on the track — for example, how much of a video is already loaded (app only)
    secondaryActiveColor color — Track color up to secondaryTrackValue (app only)
    @price:50.0
    Column spacing:4
      Slider value:$price min:0 max:100 divisions:10 label:$"${price}" activeColor:#4f46e5 inactiveColor:#c7d2fe onChanged:(value){price = value}
      Text $"No more than ${price} ₽"

    SegmentedButton

    A Material 3 segmented button: several options in one frame, the selected one highlighted and marked with a check. The options are children with id:segment and their own value ; the child itself is drawn (usually a Text ).

    Type: multi-child

    @period:"week"
    SegmentedButton selected:$period onSelectionChanged:(value){period = value}
      Text id:segment value:"day" "Day"
      Text id:segment value:"week" "Week"
      Text id:segment value:"month" "Month"
    Parameter Type Default Description
    selected string "" The selected value. With multiSelectionEnabled — several, comma-separated: "mon,wed"
    onSelectionChanged callback — Called on selection; the value argument is the selected values as a comma-separated string: (value){…} . Without it the button is disabled
    multiSelectionEnabled bool false Several segments can be selected
    showSelectedIcon bool true A check mark on selected segments
    #style ButtonStyle — Styling — the same structure as on buttons

    Parameter of a segment child:

    Parameter Type Description
    value string The segment's value — what goes into selected

    selected must name at least one segment. The button does not allow an empty selection: the initial value of the variable is one of the options.

    @days:"mon,wed"
    SegmentedButton selected:$days multiSelectionEnabled:true onSelectionChanged:(value){days = value}
      Text id:segment value:"mon" "Mon"
      Text id:segment value:"wed" "Wed"
      Text id:segment value:"fri" "Fri"

    ToggleButtons

    A row of toggle buttons in a common frame, each with its own pressed / not pressed state. The buttons are direct children (icons or text); which of them are pressed is given by isSelected — a comma-separated list of true / false in the order of the children.

    Type: multi-child

    @bold:true
    @italic:false
    ToggleButtons isSelected:$"${bold},${italic}" onPressed:(index){bold = index == 0 ? !bold : bold; italic = index == 1 ? !italic : italic}
      Icon formatBold
      Icon formatItalic
    Parameter Type Default Description
    isSelected string "" Pressed buttons: "true,false,true" . Missing ones count as not pressed, extra ones are dropped
    onPressed callback — Called on tap; the index argument is the button's number (from 0): (index){…} . The markup author toggles the state. Without it the buttons are disabled
    color color — Icon and text color of a button that is not pressed
    selectedColor color — Icon and text color of a pressed button
    fillColor color — Background of a pressed button
    disabledColor color — Icon and text color of disabled buttons
    focusColor color — Highlight on focus
    hoverColor color — Highlight on hover
    splashColor color — Ripple color on tap
    borderColor color — Border of buttons that are not pressed
    selectedBorderColor color — Border of pressed buttons
    disabledBorderColor color — Border of disabled buttons
    borderWidth double — Border thickness
    borderRadius double — Corner radius of the group (a number, not a structure)
    @align:"1,0,0"
    ToggleButtons isSelected:{align == "1,0,0" ? "true,false,false" : align == "0,1,0" ? "false,true,false" : "false,false,true"} borderRadius:8 fillColor:#4f46e5 selectedColor:#ffffff onPressed:(index){align = index == 0 ? "1,0,0" : index == 1 ? "0,1,0" : "0,0,1"}
      Icon formatAlignLeft
      Icon formatAlignCenter
      Icon formatAlignRight

    Examples

    Size and volume

    @size:"m"
    @volume:40.0
    Column spacing:12
      Row
        Radio value:"s" groupValue:$size activeColor:#4f46e5 onChanged:(value){size = value}
        Text "S"
        Radio value:"m" groupValue:$size activeColor:#4f46e5 onChanged:(value){size = value}
        Text "M"
        Radio value:"l" groupValue:$size activeColor:#4f46e5 onChanged:(value){size = value}
        Text "L"
      Slider value:$volume min:0 max:100 divisions:10 activeColor:#4f46e5 onChanged:(value){volume = value}
      Text $"Size ${size}, volume ${volume}"

    Differences between the app and the site

    • Radio on the site is a real <input type="radio"> , buttons of one group are linked; selection and onChanged work. focusColor , hoverColor are not read.
    • Slider on the site is an <input type="range"> with its own track: value , min , max , divisions , activeColor , inactiveColor , thumbColor and onChanged work. label , secondaryTrackValue , secondaryActiveColor are not read — there is no caption above the thumb and no second track.
    • SegmentedButton and ToggleButtons are drawn on the site as a still picture : a row of segments in a frame, the selected ones filled. Taps are not handled, onSelectionChanged / onPressed are not called, colors and #style are not read. The selected SegmentedButton segment is taken only from a value written directly ( selected:"week" ): with selected:$period none is selected on the site; the same goes for isSelected on ToggleButtons . On the site, choosing from options is better done with a group of Radio .

    See also