Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 2.2.3
* Fixed android location field
# 2.2.2
* Fixed android location field
# 2.2.1
* Fix crash when no url is provided on iOS
# 2.2.0
* Add support for setting URL on iOS devices
* Description and location optional

## 2.1.3
Flutter 2.10 support
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ In order to make this plugin work on iOS 10+, be sure to add this to your `info.
<string>INSERT_REASON_HERE</string>
```

`NSContactsUsageDescription` is required for the location autocomplete once Apple's UI is opened, so
it is highly recommended that you also add the key, the app might crash otherwise.

```xml
<key>NSContactsUsageDescription</key>
<string>INSERT_REASON_HERE</string>
```

## Use it

```dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ class Add2CalendarPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "add2Cal") {
val success = insert(call.argument("title")!!,
call.argument("desc")!!,
call.argument("location")!!,
call.argument("startDate")!!,
call.argument("endDate")!!,
call.argument("timeZone") as String?,
call.argument("allDay")!!,
call.argument("recurrence") as HashMap<String,Any>?,
call.argument("invites") as String?
)
result.success(success)
val success = insert(
call.argument("title")!!,
call.argument("desc") as String?,
call.argument("location") as String?,
call.argument("startDate")!!,
call.argument("endDate")!!,
call.argument("timeZone") as String?,
call.argument("allDay")!!,
call.argument("recurrence") as HashMap<String, Any>?,
call.argument("invites") as String?
)
result.success(success)

} else {
result.notImplemented()
Expand All @@ -73,16 +74,33 @@ class Add2CalendarPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
activity = null
}

private fun insert(title: String, desc:String, loc:String, start:Long, end:Long, timeZone:String?, allDay:Boolean, recurrence:HashMap<String,Any>?, invites:String?): Boolean {
private fun insert(
title: String,
desc: String?,
loc: String?,
start: Long,
end: Long,
timeZone: String?,
allDay: Boolean,
recurrence: HashMap<String, Any>?,
invites: String?
): Boolean {

val mContext: Context = if (activity != null) activity!!.applicationContext else context!!
val intent = Intent(Intent.ACTION_INSERT)


intent.data = CalendarContract.Events.CONTENT_URI
intent.putExtra(CalendarContract.Events.TITLE, title)
intent.putExtra(CalendarContract.Events.DESCRIPTION, desc)
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, loc)

if (desc != null) {
intent.putExtra(CalendarContract.Events.DESCRIPTION, desc)
}

if (loc != null) {
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, loc)
}

intent.putExtra(CalendarContract.Events.EVENT_TIMEZONE, timeZone)
intent.putExtra(CalendarContract.Events.EVENT_END_TIMEZONE, timeZone)
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start)
Expand All @@ -98,15 +116,15 @@ class Add2CalendarPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

if(intent.resolveActivity(mContext.packageManager)!= null){
if (intent.resolveActivity(mContext.packageManager) != null) {
mContext.startActivity(intent)
return true
}
return false;
}


private fun buildRRule(recurrence: HashMap<String,Any>): String? {
private fun buildRRule(recurrence: HashMap<String, Any>): String? {

var rRule = recurrence["rRule"] as String?
if (rRule == null) {
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
add_2_calendar: e9d68636aed37fb18e12f5a3d74c2e0589487af0
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -414,7 +414,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -463,7 +463,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@
<string>Create events</string>
<key>NSContactsUsageDescription</key>
<string>Add people to event</string>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
</dict>
</plist>
21 changes: 14 additions & 7 deletions ios/Classes/SwiftAdd2CalendarPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ public class SwiftAdd2CalendarPlugin: NSObject, FlutterPlugin {


let title = args["title"] as! String
let description = args["desc"] as! String
let location = args["location"] as! String
let description = args["desc"] is NSNull ? nil: args["desc"] as! String
let location = args["location"] is NSNull ? nil: args["location"] as! String
let timeZone = args["timeZone"] is NSNull ? nil: TimeZone(identifier: args["timeZone"] as! String)
let startDate = Date(milliseconds: (args["startDate"] as! Double))
let endDate = Date(milliseconds: (args["endDate"] as! Double))
let alarmInterval = args["alarmInterval"] as? Double
let allDay = args["allDay"] as! Bool
let url = (args["url"] as? String) ?? ""

let url = args["url"] as? String


let eventStore = EKEventStore()

eventStore.requestAccess(to: .event, completion: { [weak self] (granted, error) in
Expand All @@ -63,10 +64,16 @@ public class SwiftAdd2CalendarPlugin: NSObject, FlutterPlugin {
if (timeZone != nil) {
event.timeZone = timeZone
}
event.location = location
event.notes = description
if (location != nil) {
event.location = location
}
if (description != nil) {
event.notes = description
}
if let url = url{
event.url = URL(string: url);
}
event.isAllDay = allDay
event.url = URL(string: url);

if let recurrence = args["recurrence"] as? [String:Any]{
let interval = recurrence["interval"] as! Int
Expand Down
12 changes: 8 additions & 4 deletions lib/src/model/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import 'package:add_2_calendar/src/model/recurrence.dart';

/// Class that holds each event's info.
class Event {
String title, description, location;
String title;
String? description;
String? location;
String? timeZone;
DateTime startDate, endDate;
DateTime startDate;
DateTime endDate;
bool allDay;

IOSParams iosParams;
Expand All @@ -15,8 +18,8 @@ class Event {

Event({
required this.title,
this.description = '',
this.location = '',
this.description,
this.location,
required this.startDate,
required this.endDate,
this.timeZone,
Expand Down Expand Up @@ -59,5 +62,6 @@ class IOSParams {
//In iOS, you can set alert notification with duration. Ex. Duration(minutes:30) -> After30 min.
final Duration? reminder;
final String? url;

const IOSParams({this.reminder, this.url});
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: add_2_calendar
description: A really simple Flutter plugin to add events to each platform's default calendar.
version: 2.2.0
version: 2.2.3
homepage: https://github.com/ja2375/add_2_calendar

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.17.1 <3.0.0"
flutter: ">=1.20.0"

dependencies:
Expand Down