搜索分类、插件与代码仓

插件详情v4.3.3

device_calendar

一个跨平台插件,用于修改用户设备上的日历。

AndroidiOS
近 30 天下载
9.5万
喜欢数
281
Pub 分数
130

安装插件

flutter pub add device_calendar

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

device_calendar 包是一个跨平台的 Flutter 插件,可在 Android 和 iOS 上让应用与用户的设备日历进行交互。它允许直接从设备的原生日历系统读取、创建、更新和删除日历事件及日历。该插件设计用于无缝集成,在各平台上提供一致的 API,同时尊重平台特定的行为和权限。这使其非常适合需要直接访问日历的生产力、日程安排和提醒类应用程序。

适合场景

  • 安排预约
  • 创建事件提醒
  • 与设备日历同步
  • 管理日历事件
  • 构建任务管理应用

主要特点

  • 跨平台兼容性
  • 原生日历集成
  • 事件创建和删除
  • 日历权限处理
  • 平台特定行为支持

适合对象

  • 生产力应用
  • 基于日历的提醒
  • 任务管理工具
  • 活动策划软件
  • 需要日历同步的应用

使用建议

  • 两个平台均需要用户权限
  • 仅限原生日历系统
  • 在 Android 和 iOS 上的行为可能有所不同
  • 不支持 Web 或桌面端
  • 依赖于设备日历的可用性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Device Calendar Plugin

pub package Pub Version (including pre-releases) build

A cross platform plugin for modifying calendars on the user's device.

Breaking changes at v4

  • If you're upgrading from previous versions, your code will need to be modified (slightly), otherwise it will not run after update. See Timezone support for more details.
  • There are some changes to event JSON formats at v4. Pay extra care if you handle event JSONs. Directly calling to and from device calendars should be unaffected.

Features

  • Request permissions to modify calendars on the user's device
  • Check if permissions to modify the calendars on the user's device have been granted
  • Add or retrieve calendars on the user's device
  • Retrieve events associated with a calendar
  • Add, update or delete events from a calendar
  • Set up, edit or delete recurring events
    • NOTE: Editing a recurring event will currently edit all instances of it
    • NOTE: Deleting multiple instances in Android takes time to update, you'll see the changes after a few seconds
  • Add, modify or remove attendees and receive if an attendee is an organiser for an event
  • Setup reminders for an event
  • Specify a time zone for event start and end date
    • NOTE: Due to a limitation of iOS API, single time zone property is used for iOS (event.startTimeZone)
    • NOTE: For the time zone list, please refer to the TZ database name column on Wikipedia

Timezone support with TZDateTime

Due to feedback we received, starting from 4.0.0 we will be using the timezone package to better handle all timezone data.

This is already included in this package. However, you need to add this line whenever the package is needed.

import 'package:timezone/timezone.dart';

If you don't need any timezone specific features in your app, you may use flutter_native_timezone to get your devices' current timezone, then convert your previous DateTime with it.

import 'package:flutter_native_timezone/flutter_native_timezone.dart';

initializeTimeZones();

// As an example, our default timezone is UTC.
Location _currentLocation = getLocation('Etc/UTC');

Future setCurentLocation() async {
  String timezone = 'Etc/UTC';
  try {
    timezone = await FlutterNativeTimezone.getLocalTimezone();
  } catch (e) {
    print('Could not get the local timezone');
  }
  _currentLocation = getLocation(timezone);
  setLocalLocation(_currentLocation);
}

...

event.start = TZDateTime.from(oldDateTime, _currentLocation);

For other use cases, feedback or future developments on the feature, feel free to open a discussion on GitHub.

Null-safety migration

From v3.9.0, device_calendar is null-safe. However, not all workflows have been checked and bugs from older versions still persist.

You are strongly advised to test your workflow with the new package before shipping. Better yet, please leave a note for what works and what doesn't, or contribute some bug fixes!

Android Integration

The following will need to be added to the AndroidManifest.xml file for your application to indicate permissions to modify calendars are needed

<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
Proguard / R8 exceptions

NOTE: From v4.3.2 developers no longer need to add proguard rule in their app.

By default, all android apps go through R8 for file shrinking when building a release version. Currently, it interferes with some functions such as retrieveCalendars().

You may add the following setting to the ProGuard rules file proguard-rules.pro (thanks to Britannio Jarrett). Read more about the issue here

-keep class com.builttoroam.devicecalendar.** { *; }

See here for an example setup.

For more information, refer to the guide at Android Developer

AndroidX migration

Since v.1.0, this version has migrated to use AndroidX instead of the deprecated Android support libraries. When using 0.10.0 and onwards for this plugin, please ensure your application has been migrated following the guide here

iOS Integration

For iOS 10+ support, you'll need to modify the Info.plist to add the following key/value pair

<key>NSCalendarsUsageDescription</key>
<string>Access most functions for calendar viewing and editing.</string>

<key>NSContactsUsageDescription</key>
<string>Access contacts for event attendee editing.</string>

For iOS 17+ support, add the following key/value pair as well.

<key>NSCalendarsFullAccessUsageDescription</key>
<string>Access most functions for calendar viewing and editing.</string>

Note that on iOS, this is a Swift plugin. There is a known issue being tracked here by the Flutter team, where adding a plugin developed in Swift to an Objective-C project causes problems. If you run into such issues, please look at the suggested workarounds there.

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目