diff --git a/CHANGELOG.md b/CHANGELOG.md
index c3f2c14..1ae4114 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/README.md b/README.md
index ddccd23..276917e 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,14 @@ In order to make this plugin work on iOS 10+, be sure to add this to your `info.
INSERT_REASON_HERE
```
+`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
+NSContactsUsageDescription
+INSERT_REASON_HERE
+```
+
## Use it
```dart
diff --git a/android/src/main/kotlin/com/javih/add_2_calendar/Add2CalendarPlugin.kt b/android/src/main/kotlin/com/javih/add_2_calendar/Add2CalendarPlugin.kt
index 98cf263..9d9f5c6 100644
--- a/android/src/main/kotlin/com/javih/add_2_calendar/Add2CalendarPlugin.kt
+++ b/android/src/main/kotlin/com/javih/add_2_calendar/Add2CalendarPlugin.kt
@@ -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?,
- 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?,
+ call.argument("invites") as String?
+ )
+ result.success(success)
} else {
result.notImplemented()
@@ -73,7 +74,17 @@ 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?, invites:String?): Boolean {
+ private fun insert(
+ title: String,
+ desc: String?,
+ loc: String?,
+ start: Long,
+ end: Long,
+ timeZone: String?,
+ allDay: Boolean,
+ recurrence: HashMap?,
+ invites: String?
+ ): Boolean {
val mContext: Context = if (activity != null) activity!!.applicationContext else context!!
val intent = Intent(Intent.ACTION_INSERT)
@@ -81,8 +92,15 @@ class Add2CalendarPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
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)
@@ -98,7 +116,7 @@ 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
}
@@ -106,7 +124,7 @@ class Add2CalendarPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}
- private fun buildRRule(recurrence: HashMap): String? {
+ private fun buildRRule(recurrence: HashMap): String? {
var rRule = recurrence["rRule"] as String?
if (rRule == null) {
diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist
index 8d4492f..9625e10 100644
--- a/example/ios/Flutter/AppFrameworkInfo.plist
+++ b/example/ios/Flutter/AppFrameworkInfo.plist
@@ -21,6 +21,6 @@
CFBundleVersion
1.0
MinimumOSVersion
- 9.0
+ 11.0
diff --git a/example/ios/Podfile b/example/ios/Podfile
index 1e8c3c9..88359b2 100644
--- a/example/ios/Podfile
+++ b/example/ios/Podfile
@@ -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'
diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock
index 6a0c852..ad5f788 100644
--- a/example/ios/Podfile.lock
+++ b/example/ios/Podfile.lock
@@ -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
diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj
index 25bbb57..4c28160 100644
--- a/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/example/ios/Runner.xcodeproj/project.pbxproj
@@ -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;
@@ -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;
@@ -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;
diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist
index c034d08..e4a4a53 100644
--- a/example/ios/Runner/Info.plist
+++ b/example/ios/Runner/Info.plist
@@ -53,5 +53,7 @@
Create events
NSContactsUsageDescription
Add people to event
+ CADisableMinimumFrameDurationOnPhone
+
diff --git a/ios/Classes/SwiftAdd2CalendarPlugin.swift b/ios/Classes/SwiftAdd2CalendarPlugin.swift
index 729fc6c..a4171a8 100644
--- a/ios/Classes/SwiftAdd2CalendarPlugin.swift
+++ b/ios/Classes/SwiftAdd2CalendarPlugin.swift
@@ -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
@@ -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
diff --git a/lib/src/model/event.dart b/lib/src/model/event.dart
index bec6fe5..d65ca06 100644
--- a/lib/src/model/event.dart
+++ b/lib/src/model/event.dart
@@ -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;
@@ -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,
@@ -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});
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 7d1c48a..4322f15 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -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: