搜尋套件、儲存庫與 APP 分類

cupertino_calendar_picker 封面
套件詳情v3.0.0

cupertino_calendar_picker

此套件包含一組類似 Cupertino 的元件,讓日期與時間選擇更為順暢,並在視覺上與 iOS 設計原則保持一致。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.3萬
喜歡數
148
Pub 分數
160

安裝套件

flutter pub add cupertino_calendar_picker

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供類似 Cupertino 的日期與時間選擇器,確保與 iOS 設計原則一致的順暢且視覺上連貫的體驗。它為在 Android、iOS、Web、macOS、Windows 和 Linux 等多個平台選擇日期與時間提供了原生般的元件。此套件增強了針對 Apple 美學應用程式的使用者介面一致性,同時維持跨平台功能。

適用情境

  • 跨平台應用中的 iOS 風格日期選擇
  • 日程安排功能中的整合日曆視圖
  • 時間追蹤,介面一致
  • 需要選擇日期的表單輸入
  • 透過平台特定的設計提升使用者體驗
  • 適用於行動應用程式的可自訂日期選擇器

主要特色

  • Cupertino 風格的日期選擇器
  • 跨平台相容性
  • 與 Flutter 的無縫整合
  • iOS設計語言一致性
  • 可客製化的外觀
  • 對多個平台的支援

適合對象

  • 面向iOS美學的開發者
  • 需要一致日期輸入的應用程式
  • 跨平台移動應用程式
  • 注重設計的UI實現
  • 團隊優先考慮原生外觀和感覺

使用建議

  • 超出Cupertino風格的自訂功能有限
  • 可能不適合非iOS設計主題
  • 在非iOS平台需要謹慎處理
  • 對 Flutter 的 Cupertino 小部件的依賴
  • 大型日曆可能帶來的效能影響

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

The package provides a sleek and stylish cupertino calendar widgets designed to mimic the aesthetics of iOS. With smooth animations and intuitive user interactions, it seamlessly integrates into your Flutter app to deliver a delightful user experience.

Cupertino Calendar Picker     Cupertino Time Picker

Features

  • iOS Style: The cupertino calendar picker follows the design principles of iOS, ensuring consistency and familiarity for iOS users.
  • Smooth Animations: Enjoy fluid animations that enhance the overall look and feel of the calendar, providing a polished user experience.
  • Customizable: Easily customize the appearance of the calendar to match your app's theme and branding.
  • Intuitive Interactions: Users can effortlessly navigate through years, months and interact with the calendar thanks to its intuitive design.

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  cupertino_calendar_picker: ^2.2.6

Import it:

import 'package:cupertino_calendar_picker/cupertino_calendar_picker.dart';

In your CupertinoApp or MaterialApp add the localizationsDelegates

CupertinoApp(
  localizationsDelegates: const [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ],
);

Widgets

This package offers three convenient widgets for integrating pickers directly into your app.

CupertinoCalendar Widget.

The CupertinoCalendar widget provides an inline calendar that can be displayed directly within your screen.

Cupertino Inline Calendar Light     Cupertino Inline Calendar Dark

Usage Example
SizedBox(
  width: 350,
  child: CupertinoCalendar(
    minimumDateTime: DateTime(2024, 7, 10),
    maximumDateTime: DateTime(2025, 7, 10),
    initialDateTime: DateTime(2024, 8, 15, 9, 41),
    currentDateTime: DateTime(2024, 8, 15),
    timeLabel: 'Ends',
    mode: CupertinoCalendarMode.dateTime,
  ),
),
CupertinoCalendarPickerButton Widget.

The CupertinoCalendarPickerButton widget allows users to open a cupertino calendar picker when the button is pressed.

Cupertino Time Picker Button Light     Cupertino Time Picker Button Dark

Usage Example
CupertinoCalendarPickerButton(
  minimumDateTime: DateTime(2024, 7, 10),
  maximumDateTime: DateTime(2025, 7, 10),
  initialDateTime: DateTime(2024, 8, 15, 9, 41),
  currentDateTime: DateTime(2024, 8, 15),
  mode: CupertinoCalendarMode.dateTime,
  timeLabel: 'Ends',
  onDateTimeChanged: (date) {},
),
CupertinoTimePickerButton Widget.

The CupertinoTimePickerButton widget lets users select a time via the calendar time picker that appears when the button is pressed.

Cupertino Time Picker Button Light     Cupertino Time Picker Button Dark

Usage Example
CupertinoTimePickerButton(
  initialTime: const TimeOfDay(hour: 9, minute: 41),
  onTimeChanged: (time) {},
),

Functions

This package also includes two functions for displaying pickers from your widgets.

showCupertinoCalendarPicker function.

The showCupertinoCalendarPicker function displays a calendar picker around your widget.

  • From version 2.0.0, you can specify the CupertinoCalendarMode to allow selection of both date and time.
Usage Example
Future<DateTime?> onCalendarWidgetTap(BuildContext context) async {
  final RenderBox? renderBox = context.findRenderObject() as RenderBox?;
  final nowDate = DateTime.now();

  return showCupertinoCalendarPicker(
    context,
    widgetRenderBox: renderBox,
    minimumDateTime: nowDate.subtract(const Duration(days: 15)),
    initialDateTime: nowDate,
    maximumDateTime: nowDate.add(const Duration(days: 360)),
    mode: CupertinoCalendarMode.dateTime,
    timeLabel: 'Ends',
    onDateTimeChanged: (dateTime) {},
  );
}
Actions

You can add actions to the calendar picker by passing a list of CupertinoCalendarAction objects. The package provides two built-in actions: CancelCupertinoCalendarAction and ConfirmCupertinoCalendarAction.

Cupertino Calendar Picker With Actions Light     Cupertino Calendar Picker With Actions Dark

Usage Example
Future<DateTime?> onCalendarWidgetTap(BuildContext context) async {
  final RenderBox? renderBox = context.findRenderObject() as RenderBox?;
  final nowDate = DateTime.now();

  return showCupertinoCalendarPicker(
    context,
    widgetRenderBox: renderBox,
    minimumDateTime: nowDate.subtract(const Duration(days: 15)),
    initialDateTime: nowDate,
    maximumDateTime: nowDate.add(const Duration(days: 360)),
    timeLabel: 'Ends',
    actions: [
      CancelCupertinoCalendarAction(
        label: 'Cancel',
        onPressed: () {},
      ),
      ConfirmCupertinoCalendarAction(
        label: 'Done',
        isDefaultAction: true,
        onPressed: (dateTime) {},
      ),
    ],
  );
}

[!NOTE] Works only when the calendar is in the CupertinoCalendarType.compact mode.

showCupertinoTimePicker function.

The showCupertinoTimePicker function shows a time picker around your widget.

Usage Example
Future<TimeOfDay?> onTimeWidgetTap(BuildContext context) async {
  final RenderBox? renderBox = context.findRenderObject() as RenderBox?;

  return showCupertinoTimePicker(
    context,
    widgetRenderBox: renderBox,
    onTimeChanged: (time) {},
  );
}

Functions Usage Example

Call the showCupertinoCalendarPicker passing date constrains and widget's RenderBox of the widget above/below which you wish to display the calendar.

@override
Widget build(BuildContext context) {
  return CupertinoApp(
    localizationsDelegates: const [
      GlobalMaterialLocalizations.delegate,
      GlobalWidgetsLocalizations.delegate,
      GlobalCupertinoLocalizations.delegate,
    ],
    home: CupertinoPageScaffold(
      child: Builder(
        builder: (context) {
          /// Passing exactly this `BuildContext` is mandatory here to 
          /// get the `RenderBox` of the appropriate widget.
          return YourWidget(
            onTap: () => onTap(context),
          );
        },
      ),
    ),
  );
}

/// The `BuildContext` comes from the `Builder` above the widget tree.
Future<void> onTap(BuildContext context) {
  final renderBox = context.findRenderObject() as RenderBox?;
  final nowDate = DateTime.now();

  return showCupertinoCalendarPicker(
    context,
    widgetRenderBox: renderBox,
    minimumDate: nowDate.subtract(const Duration(days: 15)),
    initialDate: nowDate,
    maximumDate: nowDate.add(const Duration(days: 360)),
  );
}

How to get a RenderBox?

There are 3 simple ways of how you can get the widget's render box to pass it to the showCupertinoCalendarPicker or showCupertinoTimePicker function.

You can choose any of these.

  1. Wrap your widget with Builder widget.
Builder(
  builder: (context) {
    return YourWidget(
      onTap: () => onTap(context),
    );
  },
);

Future<void> onTap(BuildContext context) {
  /// And here you can get the `RenderBox` of your widget 
  /// using the `Builder`s `BuildContext`
  final renderBox = context.findRenderObject() as RenderBox?;
  return showCupertinoCalendarPicker(...);
}

  1. Use a GlobalKey.
final globalKey = GlobalKey();

@override
Widget build(BuildContext context) {
  return CupertinoApp(
    localizationsDelegates: const [
      GlobalMaterialLocalizations.delegate,
      GlobalWidgetsLocalizations.delegate,
      GlobalCupertinoLocalizations.delegate,
    ],
    home: CupertinoPageScaffold(
      child: YourWidget(
        key: globalKey,
        onTap: onTap,
      ),
    ),
  );
}

Future<void> onTap(BuildContext context) {
  /// And here you can get the `RenderBox` of your widget using the `GlobalKey`.
  final renderBox = globalKey.currentContext?.findRenderObject() as RenderBox?;
  return showCupertinoCalendarPicker(...);
}

  1. Pass a BuildContext directly from your widget's build method.
class YourWidget extends StatelessWidget {
  const YourWidget({
    required this.onTap,
  });

  final void Function(BuildContext context) onTap;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => onTap(context),
      child: ...,
    );
  }
}

Future<void> onTap(BuildContext context) {
  /// And here you can get the `RenderBox` of your widget's `build` method.
  final renderBox = context.findRenderObject() as RenderBox?;
  return showCupertinoCalendarPicker(...);
}

Maintainers

Philip Dmitruk

所屬分類

依賴

依賴清單 4 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。