Picker class

A customizable picker widget for Flutter applications.

The Picker class provides a flexible and customizable way to present selection interfaces to users. It supports multiple columns, various data adapters, and extensive customization options.

Features

  • Multiple column support with custom flex ratios
  • Various data adapters (arrays, numbers, date/time)
  • Extensive styling and theming options
  • Multiple presentation modes (modal, dialog, bottom sheet)
  • Internationalization support
  • Custom item builders and formatting
  • Loop scrolling and smooth animations

Basic Usage

final picker = Picker(
  adapter: PickerDataAdapter<String>(
    pickerData: ['Option 1', 'Option 2', 'Option 3'],
  ),
  onConfirm: (picker, selected) {
    print('Selected: ${picker.getSelectedValues()}');
  },
);

picker.showModal<List<int>>(context);

Advanced Usage with Multiple Columns

final picker = Picker(
  adapter: PickerDataAdapter<String>(
    pickerData: [
      {'Fruits': ['Apple', 'Banana', 'Orange']},
      {'Colors': ['Red', 'Green', 'Blue']},
    ],
  ),
  title: Text('Choose Fruit and Color'),
  columnFlex: [2, 1], // First column takes 2/3, second takes 1/3
  onConfirm: (picker, selected) {
    final values = picker.getSelectedValues();
    print('Selected fruit: ${values[0]}, color: ${values[1]}');
  },
);

See also:

Constructors

Picker({required PickerAdapter adapter, List<PickerDelimiter>? delimiter, List<int>? selecteds, double height = 150.0, double itemExtent = 28.0, EdgeInsetsGeometry? columnPadding, TextStyle? textStyle, TextStyle? cancelTextStyle, TextStyle? confirmTextStyle, TextStyle? selectedTextStyle, IconThemeData? selectedIconTheme, TextAlign textAlign = TextAlign.start, TextScaler? textScaler, Widget? title, Widget? cancel, Widget? confirm, String? cancelText, String? confirmText, Color? backgroundColor, Color? containerColor, Color? headerColor, WidgetBuilder? builderHeader, bool changeToFirst = false, bool hideHeader = false, bool looping = false, bool reversedOrder = false, Decoration? headerDecoration, List<int>? columnFlex, Widget? footer, int smooth = 0, double magnification = 1.0, double diameterRatio = 1.1, double squeeze = 1.45, Widget selectionOverlay = const CupertinoPickerDefaultSelectionOverlay(), PickerItemBuilder? onBuilderItem, VoidCallback? onCancel, PickerSelectedCallback? onSelect, PickerConfirmBeforeCallback? onConfirmBefore, PickerConfirmCallback? onConfirm, bool printDebug = false})

Properties

adapter ↔ PickerAdapter
The data adapter that provides content and manages the picker's data.
getter/setter pair
backgroundColor → Color?
final
builderHeader → WidgetBuilder?
Custom builder for the picker header.
final
cancel → Widget?
final
cancelText → String?
final
cancelTextStyle → TextStyle?
final
changeToFirst → bool
Whether to automatically scroll child columns to the first item when parent selection changes.
final
columnFlex → List<int>?
Custom flex values for each picker column.
final
columnPadding → EdgeInsetsGeometry?
final
confirm → Widget?
final
confirmText → String?
final
confirmTextStyle → TextStyle?
final
containerColor → Color?
final
delimiter → List<PickerDelimiter>?
Optional list of delimiters to insert between picker columns.
final
diameterRatio → double
final
final
hashCode → int
The hash code for this object.
no setterinherited
headerColor → Color?
final
headerDecoration → Decoration?
final
height → double
final
hideHeader → bool
Whether to hide the picker header (title, cancel, and confirm buttons).
final
itemExtent → double
The height of each picker item in logical pixels.
final
looping → bool
Whether picker items should loop infinitely when scrolling.
final
magnification → double
final
onBuilderItem → PickerItemBuilder?
Custom builder for individual picker items.
final
onCancel → VoidCallback?
final
onConfirm → PickerConfirmCallback?
final
onConfirmBefore → PickerConfirmBeforeCallback?
final
onSelect → PickerSelectedCallback?
final
printDebug → bool
final
reversedOrder → bool
Whether to display picker columns in reverse order.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
selectedIconTheme → IconThemeData?
final
selecteds ↔ List<int>
List of currently selected item indices for each column.
getter/setter pair
selectedTextStyle → TextStyle?
final
selectionOverlay → Widget
A widget overlaid on the picker to highlight the currently selected entry.
final
smooth → int
Delay in milliseconds before building picker content for smoother animations.
final
squeeze → double
final
state → PickerWidgetState?
no setter
textAlign → TextAlign
final
textScaler → TextScaler?
Controls how text in the picker scales with the system font size.
final
textStyle → TextStyle?
final
title → Widget?
final
widget → Widget?
no setter

Methods

doCancel(BuildContext context) → void
Cancel
doConfirm(BuildContext context) → void
Confirm
getSelectedValues() → List
Gets the currently selected values from the picker.
makePicker([ThemeData? themeData, bool isModal = false, Key? key]) → Widget
Creates the picker widget with optional theme and modal configuration.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
show(ScaffoldState state, {ThemeData? themeData, Color? backgroundColor, PickerWidgetBuilder? builder}) → void
Shows the picker in a bottom sheet using the provided scaffold state.
showBottomSheet(BuildContext context, {ThemeData? themeData, Color? backgroundColor, PickerWidgetBuilder? builder}) → void
Shows the picker in a persistent bottom sheet.
showDialog(BuildContext context, {bool barrierDismissible = true, Color? backgroundColor, PickerWidgetBuilder? builder, Key? key}) → Future<List<int>?>
show dialog picker
showModal<T>(BuildContext context, {ThemeData? themeData, bool isScrollControlled = false, bool useRootNavigator = false, Color? backgroundColor, ShapeBorder? shape, Clip? clipBehavior, PickerWidgetBuilder? builder}) → Future<T?>
Displays the picker in a modal bottom sheet.
toString() → String
A string representation of this object.
inherited
updateColumn(int index, [bool all = false]) → void
Force update the content of specified column When modifying the content of columns before the current column in the onSelect event, this method can be called to update the display

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

defaultTextSize → const double