패키지, 저장소 및 앱 카테고리 검색

flutter_material_pickers 표지
패키지 상세v3.7.0

flutter_material_pickers

Material 테마의 피커 대화 상자를 간편하고 일관되게 표시하기 위한 Flutter 패키지입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.7천
좋아요
232
Pub 점수
130

패키지 설치

flutter pub add flutter_material_pickers

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Android, iOS, 웹, macOS, Windows, Linux용으로 일관된 매터리얼 테마의 피커 다이얼로그를 제공하는 플러터 패키지입니다. 통합 API를 통해 네이티브 스타일의 날짜, 시간 및 사용자 정의 피커를 쉽게 통합할 수 있습니다. 이 패키지는 매터리얼 디자인 원칙을 유지하면서 플랫폼 간 시각적 조화를 보장합니다. 개발자는 봐일러플레이트 코드 없이 날짜, 시간 및 사용자 정의 옵션용 피커를 쉽게 구현할 수 있습니다. 라이트 모드와 다크 모드 모두 지원하며, 해당되는 경우 플랫폼별 특성에 맞게 적응합니다.

사용 사례

  • 양식에서 날짜 선택
  • 예약 시간 선택
  • 피커 UI 맞춤설정
  • 일관된 스타일로 폼 입력 만들기
  • 크로스 플랫폼 날짜/시간 선택기 만들기

주요 기능

  • Material Design 준수
  • 크로스 플랫폼 지원
  • 간편한 통합
  • 테마 인식 렌더링
  • 사용자 정의 가능한 피커 콘텐츠
  • 다중 플랫폼 간 일관된 사용자 경험

적합한 대상

  • 폼 빌더
  • 날짜/시간 선택 기능
  • 크로스 플랫폼 앱
  • UI 일관성 프로젝트
  • 간단한 피커 솔루션을 찾는 개발자

고려 사항

  • Material 앱 컨텍스트가 필요합니다
  • 테마 외의 사용자 지정은 제한적
  • 복잡한 사용 사례를 위해 추가적인 스타일링이 필요할 수 있습니다
  • 비 매터리얼 디자인 시스템에 적합하지 않음
  • 플랫폼별 동작은 약간 다를 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Flutter Material Pickers

Pub Package GitHub stars GitHub forks GitHub repo size

CodeFactor Open Bugs Enhancement Requests Closed Issues

Buy Me A Coffee PRs Welcome Contributors License

A flutter package containing commonly used material design picker dialogs. Some are new, some wrap existing or built in pickers with a common dialog and access function.

It includes:

  • New Pickers
    • showMaterialScrollPicker:
      • Allows selection of a string via a slot machine carousel
    • showMaterialNumberPicker:
      • Allows selection of a number via a slot machine carousel
    • showMaterialRadioPicker:
      • Allows selection of a single from a radio list
    • showMaterialCheckboxPicker:
      • Allows selection of many values from a checkbox list
    • showMaterialSelectionPicker:
      • Allows selection of a single value via an icon label list
  • Convenience Pickers
    • showMaterialDatePicker:
      • Allows selection of a date (uses the core date picker)
    • showMaterialTimePicker:
      • Allows selection of a time (uses the core time picker)
    • showMaterialColorPicker:
      • Allows RGB selection of a color (uses the ColorPicker of flutter_colorpicker)
    • showMaterialPalettePicker:
      • Allows Material palette selection of a color (uses the MaterialPicker of flutter_colorpicker)
    • showMaterialSwatchPicker:
      • Allows selection of a color from swatches (uses the BlockPicker of flutter_colorpicker)
    • showMaterialFilePicker:
      • Allows selection of a file using the device's default picker
  • Dialog
    • showMaterialResponsiveDialog:
      • Extends Dialog by making it responsive to screen orientation changes

All helpers implement an onChange handler to return picked option(s). All helpers return Future<T> with the picked option(s).

There are some breaking changes in 3.0.0 (from 2.1.1).

  • Pickers accept generic types passed to pickers and helpers.
  • There's no need to pass several lists (items, values, icons), just pass one list of generic type objects.
  • A selected item of generic type is passed as selectedItem not selectedValue to match name of items.
  • To convert an item to a string displayed to a user either override toString() in generic type class or pass transformer callback which accepts an item and returns a String. (see examples)
  • To provide item's icon in SelectionPicker (and alikes), pass iconizer callback which accepts an item and returns an Icon. (see example)

Example Usage

Empty Dialog Example

Although not a picker, per se, the showMaterialEmptyPicker helper displays the universal material design dialog wrapper that the pickers appear in. Using this directly, however, allows any content to be injected into the content area by passing in a custon Widget as the child. This code shows the basic structure of all the helpers:

showMaterialResponsiveDialog(
    context: context,
    child: Center(
        child: Container(
            padding: EdgeInsets.all(30.0),
            child: Text('Any content here.'),
            style: TextStyle(
                fontSize: 20.0,
                fontStyle: FontStyle.italic,
            ),
        ),
    ),
);
Scroll Picker Example

class StateModel {
  const StateModel(this.name, this.code);
  final String code;
  final String name;

  @override
  String toString() => name;
}
static const List<StateModel> usStates = <StateModel>[
  StateModel('Alabama', 'AL'),
  StateModel('Alaska', 'AK'),
  StateModel('Arizona', 'AZ'),
  StateModel('Arkansas', 'AR'),
  StateModel('California', 'CA'),
  StateModel('Colorado', 'CO'),
  StateModel('Connecticut', 'CT'),
  ...
];
StateModel selectedUsState = usStates[0];

showMaterialScrollPicker<StateModel>(
    context: context,
    title: 'Pick Your State',
    items: usStates,
    selectedItem: selectedUsState,
    onChanged: (value) => setState(() => selectedUsState = value),
);
Number Picker Example

var age = 25;

showMaterialNumberPicker(
  context: context,
  title: 'Pick Your Age',
  maxNumber: 100,
  minNumber: 14,
  selectedNumber: age,
  onChanged: (value) => setState(() => age = value),
);
Checkbox Picker Example

class ToppingModel {
  const ToppingModel(this.name, this.code);
  final String code;
  final String name;

  @override
  String toString() => name;
}
static const List<ToppingModel> iceCreamToppings = <ToppingModel>[
  ToppingModel('Hot Fudge', 'FUDGE'),
  ToppingModel('Sprinkles', 'SPRINK'),
  ToppingModel('Caramel', 'CARM'),
  ToppingModel('Oreos', 'OREO'),
  ...
];
List<ToppingModel> selectedIceCreamToppings = [
  iceCreamToppings[0],
  iceCreamToppings[2],
];

showMaterialCheckboxPicker<ToppingModel>(
  context: context,
  title: 'Pick Your Toppings',
  items: iceCreamToppings,
  selectedItems: selectedIceCreamToppings,
  onChanged: (value) => setState(() => selectedIceCreamToppings = value),
);
Radio Picker Example

class StateModel {
  const StateModel(this.name, this.code);
  final String code;
  final String name;

  @override
  String toString() => name;
}
static const List<StateModel> usStates = <StateModel>[
  StateModel('Alabama', 'AL'),
  StateModel('Alaska', 'AK'),
  StateModel('Arizona', 'AZ'),
  StateModel('Arkansas', 'AR'),
  StateModel('California', 'CA'),
  StateModel('Colorado', 'CO'),
  StateModel('Connecticut', 'CT'),
  ...
];
StateModel selectedUsState = usStates[3];

showMaterialRadioPicker<StateModel>(
  context: context,
  title: 'Pick Your State',
  items: usStates,
  selectedItem: selectedUsState,
  onChanged: (value) => setState(() => selectedUsState = value),
);
Selection Picker Example

class SpeedModel {
  const SpeedModel(this.name, this.icon);
  final String name;
  final Icon icon;
}
// Selection Picker Model
static const List<SpeedModel> speedOptions = <SpeedModel>[
  SpeedModel('Light', Icon(Icons.sort)),
  SpeedModel('Ridiculous', Icon(Icons.clear_all)),
  SpeedModel('Ludicrous', Icon(Icons.swap_calls)),
  SpeedModel('Plaid', Icon(Icons.select_all)),
];
SpeedModel speed = speedOptions[2];

showMaterialSelectionPicker(
  context: context,
  title: "Starship Speed",
  items: speedOptions,
  selectedItem: speed,
  icons: speedIcons,
  transformer: (item) => item.name,
  iconizer: (item) => item.icon,
  onChanged: (value) => setState(() => speed = value),
);
Time Picker Example

var time = TimeOfDay.now();

showMaterialTimePicker(
  context: context,
  selectedTime: time,
  onChanged: (value) => setState(() => time = value),
);
Date Picker Example

var date = DateTime.now();

showMaterialDatePicker(
  context: context,
  selectedDate: date,
  onChanged: (value) => setState(() => date = value),
);
Color Picker Example

Color color = Colors.red;

showMaterialColorPicker(
  context: context,
  selectedColor: color,
  onChanged: (value) => setState(() => color = value),
);
Palette Picker Example

Color palette = Colors.green;

showMaterialPalettePicker(
  context: context,
  selectedColor: palette,
  onChanged: (value) => setState(() => palette = value),
);
Swatch Picker Example

Color swatch = Colors.blue;

showMaterialSwatchPicker(
  context: context,
  selectedColor: swatch,
  onChanged: (value) => setState(() => swatch = value),
);

Picker Model

If you don't already have or want to build a custom object to hold selction items, this library includes a general purpose one called PickerModel that you would use like this:

  static const List<PickerModel> items = <PickerModel>[
    PickerModel('First', code: 1, icon: Icon(Icons.sort)),
    PickerModel('Second', code: 2, icon: Icon(Icons.clear_all)),
    PickerModel('Third', code: 3, icon: Icon(Icons.swap_calls)),
    PickerModel('Fourth', code: 4, icon: Icon(Icons.select_all)),
  ];

The code and icon fields are optional.

Theming

It is highly recommended you use Flutter's built in theme styling with primarySwatch to automatically style all controls across your entire application.

ThemeData(
  primarySwatch: Colors.indigo,
)

If you desire to override the color for a given control, here is how to customize the theme:

var theme = ThemeData();
theme = theme.copyWith(
  primaryColor: Colors.green, // background color of the header area
  accentColor: Colors.black, // color of selected controls and button bar text
  dialogBackgroundColor: Colors.green[300], // background color of the entire dialog
  primaryTextTheme: theme.primaryTextTheme.copyWith(
    title: theme.primaryTextTheme.title.copyWith(
      color: Colors.lightGreen[50], // text color of the header area
    ),
  ),
  textTheme: theme.textTheme.copyWith(
    body1: theme.textTheme.body1.copyWith(
      color: Colors.green[900], // text color of dialog text
    ),
    button: theme.textTheme.button.copyWith(
      color: Colors.lightGreen[50], // text color of the action bar buttons
    ),
  ),
);

The example app demonstrates switching between light and dark themes globally.

However, if for some reason you want to change colors in an individual dialog, several parameters are exposed to allow this:

showMaterialResponsiveDialog(
    context: context,
    headerColor: Colors.green, // background color of the header area
    headerTextColor: Colors.white, // text fcolor of the header
    backgroundColor: Colors.lightGreen, // background color of the entire dialog
    buttonTextColor: Colors.red, // text color of the action bar buttons
    child: Text('Custom dialog colors'),
);

Customization

You can customize the text that appears in various areas of the screen. The button labels automatically localize to the native language versions of "Ok" and "Cancel", unless replacement text is provided.

showMaterialNumberPicker(
  title: 'Pick Your Age',
  confirmText: 'Count me in',
  cancelText: 'Negatory',
);

Sizing

To prevent dialogs from growing to full screen on larger devices (or web) two properties control the maxmium size that it will grow:

  maxLongSide: 600,
  maxShortSide: 400,

The sides relate to if the dialog is showing in landscape or portrait mode. If you wish larger (or smaller) dialogs you can overide these values.

Supported Platforms

  • [x] Android
  • [x] iOS
  • [x] Web

Dependencies

This widget set relies on these external third-party components:

Changelog

Please see the Changelog page to know what's recently changed.

Contributions

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.

If you fixed a bug or implemented a new feature, please send a pull request. Please include a note about your change in CHANGELOG.md with your pull request.

카테고리

의존성

의존성 목록 3 개

소스 저장소

이 패키지를 사용하는 프로젝트