Contents
Coding With Dhrumil

HomeArticles

Flutter Cupertino Segmented Control: A Practical Guide

By Dhrumil PatelPublished 3 min read

CupertinoSegmentedControl is the iOS-style picker you see above lists in Settings, Mail, and the App Store: a rounded track of two to five labels where exactly one stays selected. In Flutter it is a single widget that handles the selection state for you, so most of the work is deciding what belongs in each segment and how wide the control should get.

This guide walks through a working example, then covers the details that bite people in production: label length, thumb and border theming, keeping state across rebuilds, and when a segmented control is the wrong choice compared with tabs or a plain toggle.

A Minimal Working Example

Start with a stateful widget and a single generic type. The control takes a map from value to child widget, plus the currently selected value and an onValueChanged callback. Keeping the type as an enum rather than a string means the compiler catches typos and you get exhaustive switches later.

Wrap the control in a SizedBox or Padding so it does not stretch edge to edge on tablets. On a phone, roughly 16 to 24 logical pixels of horizontal padding matches iOS behaviour and keeps the rounded ends visible. Below about 280 logical pixels of available width, three segments start to feel cramped, so plan labels of one or two short words.

  • Map of value to Text child, one entry per segment
  • selectedValue held in setState or a state manager
  • onValueChanged updates state and triggers your content switch
  • Constrain width with SizedBox or Padding on larger screens

Sizing, Labels, and Touch Targets

Segments size themselves to their content, which means uneven label lengths produce uneven segments. iOS itself allows this, but if you want equal widths you have to give every child the same intrinsic width, usually by wrapping each Text in a SizedBox with a fixed width derived from the longest label. Measure at a large text scale before you hardcode anything.

Height matters more than width for usability. The default control sits around 32 logical pixels tall, below the 44 to 48 pixel touch target guidelines on iOS and Android respectively. Wrapping it in a GestureDetector does not fix that; instead add vertical padding inside the child widgets or place the control inside a Container with extra padding so the tappable area grows.

  • Two to five segments is the comfortable range
  • Avoid dynamic labels that change length after selection
  • Test at 1.3x and 2.0x text scale
  • Keep the tap area near 44 logical pixels tall

Theming the Thumb, Border, and Text

CupertinoSegmentedControl exposes selectedColor, unselectedColor, borderColor, pressedColor, and disabledColor, plus childOnColor and childOffColor for the label text. If you leave them null, the widget pulls from CupertinoTheme, which is usually what you want so the control matches the rest of an iOS-styled screen.

A common mistake is setting a saturated selectedColor while leaving the label colour dark, which kills contrast. Aim for at least a 4.5:1 ratio between text and thumb. If your app is Material-first but you want this look on one screen, remember the control will still read Cupertino colours, so pass explicit values or you will get a mismatched palette. Mixing the two design languages is covered in Cupertino vs Material Widgets: Which Style Fits Your App?.

Choosing between common Flutter selection widgets
WidgetTypical optionsBest forTap targetFeels native on
CupertinoSegmentedControl2-5Switching views of one data set~32 dp defaultiOS
SegmentedButton (Material 3)2-5Same role, Material styling~40 dp defaultAndroid
TabBar2-7Top-level page navigation~46 dpBoth
CupertinoSwitch2On/off settings~51x31 dpiOS
DropdownMenu5+Long or dynamic option lists~48 dpBoth

Handling State and Rebuilds

The control is stateless from your perspective: it renders whatever selectedValue you pass. That is good, because it means the source of truth lives in your widget, provider, or view model. The catch is that any ancestor rebuild must supply the same value, or the thumb jumps back. If you rebuild from a stream or a FutureBuilder, hold the selection in a field rather than recomputing it.

When the segmented control drives a list below it, avoid rebuilding the entire page. Wrap only the changing content in an AnimatedSwitcher or a keyed widget so the control itself does not repaint. If you are also handling rotation or keyboard insets, the state-loss patterns in Handling Configuration Changes in Kotlin Without Losing State map neatly onto Flutter's own restoration problem.

  • Keep selection in one place, pass it down
  • Use a keyed child so switching segments swaps content cleanly
  • Persist the selection if the screen can be restored after process death

When Not to Use a Segmented Control

A segmented control is for mutually exclusive views of the same data, not for navigation between unrelated screens. If tapping a segment changes the whole page hierarchy, use a TabBar or a bottom navigation bar instead. If the options are more than about five, or the labels need a sentence, a dropdown or a filter sheet is kinder to users.

For binary choices, a CupertinoSwitch is faster to read and easier to hit. For multi-select filters, segmented controls simply do not apply. The decision usually comes down to how many options there are and whether the user needs to see all of them at once.

  • Use for 2-5 exclusive views of the same content
  • Use tabs for top-level navigation
  • Use a switch for on/off
  • Use a sheet or dropdown beyond five options
32Cupertino segmente40Material 3 segment44iOS minimum48Android minimum
Default control height vs recommended minimum touch target (logical pixels)

Key points

  • CupertinoSegmentedControl is stateless: you own the selected value
  • Keep it to two to five short labels for comfortable layout
  • Default height is below touch guidelines, so add padding
  • Reach for tabs or a switch when the job is navigation or on/off

Flutter Screen Widget and Cost Estimator

Estimate the number of widgets in a screen and a rough development-hour figure from your component counts. Adjust the fields to see how each UI area affects the total effort.

Calculate

Dhrumil Patel

Editor and Flutter contributor

Writes practical Flutter tutorials focused on widgets, layout and animation. Enjoys breaking large UI problems into small, testable pieces and explaining them clearly to beginners.

Related articles

Jetpack Navigation vs Manual Fragment Transactions

Explains when the Navigation component pays off and when plain transactions are enough.

What Does a Flutter App Cost to Build in 2026?

Breaks down typical hours and cost ranges by feature set for small Flutter apps.

How Many Widgets Does a Typical Flutter Screen Really Use?

Counts the widget tree size of common screen patterns and explains why composition beats deep nesting.