Code Monkey home page Code Monkey logo

persistent_device_calendar's Introduction

Persistent Device Calendar

Features

This package contains a wrapper for the device_calendar plugin which adds persistence and quality-of-life improvements, reducing boilerplate code in common use-cases, as well as improving code readability and simplicity.

NOTE: This package currently only aims to provide basic calendar functionality, recurrence for events has not been tested with this package and is considered not supported.

Example

void usage() async {
  var calPlugin = PersistentDeviceCalendar();
  if (!await calPlugin.setup()) return; // Setup permissions or return if not granted
  
  var start = TZDateTime.now(getLocation("America/Detroit")); // Constant debug times
  var end = start.add(const Duration(hours: 2));
  
  var calendar = await calPlugin.getCalendar<CustomEvent>(name: "Custom Events",
      builder: (event, calendarId, eventId) => Event(calendarId, eventId: eventId, title: event.name, start: start, end: end),
      idSelector: (event) => event.id
  );
  await calendar.prune(); // Optionally remove registered events which have been deleted on the device

  var events = [
    CustomEvent(id: "a", name: "Event A"),
    CustomEvent(id: "b", name: "Event B"), 
    CustomEvent(id: "c", name: "Event C")
  ];
  await calendar.put(events); // Put events, possibly replacing old version
}

class CustomEvent {

  String id;
  String name;

  CustomEvent({
    required this.id,
    required this.name,
  });
}

Timezones with TZDateTime (from device_calendar)

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';

// 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.

Platform Setup (from device_calendar)

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

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>

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.

persistent_device_calendar's People

Contributors

helightdev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.