Skip to main content

antd_picker 1.0.1 copy "antd_picker: ^1.0.1" to clipboard
antd_picker: ^1.0.1 copied to clipboard

Ant Design picker, cascader, date and time pickers for Flutter, with wheel columns and antd-mobile v5 interaction.

antd_picker - Wheel pickers, cascader, and date/time pickers for Flutter #

English | 简体中文

Positioning & design #

antd_picker groups the selection surfaces that share a modal bottom-sheet or overlay container: AntPicker<T> for one or more wheel columns, AntCascader<T> for hierarchical drill-down selection, and AntDatePicker / AntTimePicker for formatted date and time fields. All generic pickers read your model T through dataSource, keyOf, and labelBuilder; nothing is flattened into string labels.

Design rules:

  • Values are typed. AntPicker<T> confirms a List<T> — one selected object per column — while cascaders report the selected path.
  • Wheels are data-driven. A column is AntPickerColumn<T>; column count and item rendering are declarations.
  • The trigger is yours. Pickers accept a child widget that opens the sheet, so any button, field, or card can be the entry point.
  • Date and time stay separate. AntDatePicker works in DateTime, AntTimePicker in TimeOfDay, each with its own display format / step controls.

Installation #

Requires Dart >=3.0.0 and Flutter >=3.10.0.

dependencies:
  antd_picker: ^1.0.0

Wrap the subtree in AntTheme; wheel highlight, sheet chrome, and field borders come from the design tokens:

AntTheme(
  data: AntThemeData.light(),
  child: MaterialApp(home: YourPage()),
)

Quick start #

import 'package:antd_picker/antd_picker.dart';
import 'package:antd_theme/antd_theme.dart';
import 'package:material_ui/material_ui.dart';

class Season {
  const Season(this.id, this.name);

  final int id;
  final String name;
}

const seasons = <Season>[
  Season(1, 'Spring'),
  Season(2, 'Summer'),
  Season(3, 'Autumn'),
  Season(4, 'Winter'),
];

void main() => runApp(
      AntTheme(
        data: AntThemeData.light(),
        child: MaterialApp(
          home: Scaffold(
            body: Center(
              child: AntPicker<Season>(
                title: 'Season',
                columns: [
                  AntPickerColumn<Season>(
                    dataSource: seasons,
                    keyOf: (season) => season.id,
                    labelBuilder: (context, season) => Text(season.name),
                  ),
                ],
                onConfirm: (values) {
                  debugPrint('picked ${values.first.name}');
                },
                child: const Padding(
                  padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
                  child: Text('Pick a season'),
                ),
              ),
            ),
          ),
        ),
      ),
    );

Tapping the child opens the wheel sheet. Confirm reports the selected Season objects in column order, and cancel dismisses without a value.

API #

API reference

1. A two-column year/month picker #

class MonthPicker extends StatefulWidget {
  const MonthPicker({super.key});

  @override
  State<MonthPicker> createState() => _MonthPickerState();
}

class _MonthPickerState extends State<MonthPicker> {
  int _year = 2025;
  int _month = 3;

  @override
  Widget build(BuildContext context) {
    return AntPicker<int>(
      title: 'Month',
      confirmText: 'OK',
      cancelText: 'Cancel',
      defaultValue: <int>[_year, _month],
      columns: [
        AntPickerColumn<int>(
          dataSource: List<int>.generate(10, (index) => 2021 + index),
          keyOf: (year) => year,
          labelBuilder: (context, year) => Text('$year'),
        ),
        AntPickerColumn<int>(
          dataSource: List<int>.generate(12, (index) => index + 1),
          keyOf: (month) => month,
          labelBuilder: (context, month) => Text('$month'),
        ),
      ],
      onConfirm: (values) => setState(() {
        _year = values[0];
        _month = values[1];
      }),
      child: Text('$_year-$_month'),
    );
  }
}

Each column confirms exactly one T, and the result keeps column order. defaultValue entries may be either T values or the keys returned by keyOf.

2. Cascading selection with a tree #

class Region {
  const Region(this.code, this.name, {this.children = const <Region>[]});

  final String code;
  final String name;
  final List<Region> children;
}

const regions = <Region>[
  Region(
    'zj',
    'Zhejiang',
    children: [
      Region('hz', 'Hangzhou'),
      Region('nb', 'Ningbo'),
    ],
  ),
  Region(
    'js',
    'Jiangsu',
    children: [
      Region('nj', 'Nanjing'),
    ],
  ),
];

AntCascader<Region>(
  dataSource: regions,
  keyOf: (region) => region.code,
  childrenOf: (region) => region.children,
  labelBuilder: (context, region) => Text(region.name),
  placeholder: 'Select a region',
  allowClear: true,
  changeOnSelect: false,
  onChange: (path) => debugPrint(path.map((r) => r.name).join(' / ')),
)

The cascader drills through childrenOf; with changeOnSelect: false a parent tab only expands the next column, and the value is committed when a leaf is chosen. AntCascaderView renders the same columns inline when you need the panel without a popup.

3. Date and time fields #

class DateTimeForm extends StatefulWidget {
  const DateTimeForm({super.key});

  @override
  State<DateTimeForm> createState() => _DateTimeFormState();
}

class _DateTimeFormState extends State<DateTimeForm> {
  DateTime? _date = DateTime(2025, 3, 18);
  TimeOfDay? _time = const TimeOfDay(hour: 9, minute: 30);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        AntDatePicker(
          value: _date,
          format: 'yyyy-MM-dd',
          placeholder: 'Pick a date',
          onChange: (date) => setState(() => _date = date),
        ),
        const SizedBox(height: 12),
        AntTimePicker(
          value: _time,
          minuteStep: 5,
          placeholder: 'Pick a time',
          onChange: (time) => setState(() => _time = time),
        ),
      ],
    );
  }
}

Both fields open their own sheet and report null when cleared (allowClear: true enables the clear affordance). minuteStep / hourStep thin out the wheel options for coarse scheduling.

Demo #

Project structure #

packages/antd_picker/
├── lib/
│   ├── antd_picker.dart                 # barrel export
│   └── src/
│       ├── picker/                      # wheel sheet and column model
│       ├── cascader/                    # cascading field and inline view
│       ├── date_picker/                 # DateTime field
│       └── time_picker/                 # TimeOfDay field
├── example/lib/main.dart                # runnable gallery
├── docs/api-index.md                    # generated API index
└── README.md

License #

MIT. See the repository LICENSE.

☕ Buy Me a Coffee #

If this project has been helpful to you, you are welcome to buy me a coffee. Thank you for your support!

Alipay WeChat
Alipay QR code WeChat QR code
0
likes
160
points
--
downloads

Documentation

API reference

Publisher

unverified uploader

Ant Design picker, cascader, date and time pickers for Flutter, with wheel columns and antd-mobile v5 interaction.

Homepage
Repository (GitHub)
View/report issues

Topics

#ui #components #design-system #ant-design #picker

License

MIT (license)

Dependencies

antd_flutter_ui, antd_icons_flutter, antd_theme, cupertino_ui, flutter, material_ui

More

Packages that depend on antd_picker