device_calendar 0.0.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new50

Device Calendar Plugin

pub package Build Status

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

Features

  • Ability to request permissions to modify calendars on the user's device
  • Ability to check if permissions to modify the calendars on the user's device have been granted
  • Retrieve calendars on the user's device
  • Retrieve events associated with a calendar
  • Ability to add, update or delete events from a calendar

Android Integration

The following will need to be added to the manifest file for your application to indicate permissions to modify calendars a needed

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

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>INSERT_REASON_HERE</string>

0.0.6 - 18th June 2018

  • [iOS] Fix an issue when adding/updating an event with a null description

0.0.5 - 14th June 2018

  • [Android] Fixed an issue with retrieving events by id only

0.0.4 - 12th June 2018

  • Reordering changelog
  • Creating new example for the Pub Dart Example tab
  • Moving existing example to the example_app GitHub folder

0.0.2 - 0.0.3 - 7th June 2018

  • Fixing incorrect Travis build links

0.0.1 - 7th June 2018

  • Ability to retrieve device calendars
  • CRUD operations on calendar events

example/lib/main.dart

import 'dart:async';

import 'package:device_calendar/device_calendar.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Device Calendar Example',
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  MyHomePageState createState() {
    return new MyHomePageState();
  }
}

class MyHomePageState extends State<MyHomePage> {
  DeviceCalendarPlugin _deviceCalendarPlugin;

  List<Calendar> _calendars;
  Calendar _selectedCalendar;
  List<Event> _calendarEvents;

  MyHomePageState() {
    _deviceCalendarPlugin = new DeviceCalendarPlugin();
  }

  @override
  initState() {
    super.initState();
    _retrieveCalendars();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Welcome to Device Calendar Example'),
      ),
      body: new Column(
        children: <Widget>[
          new ConstrainedBox(
            constraints: new BoxConstraints(maxHeight: 150.0),
            child: new ListView.builder(
              itemCount: _calendars?.length ?? 0,
              itemBuilder: (BuildContext context, int index) {
                return new GestureDetector(
                  onTap: () async {
                    await _retrieveCalendarEvents(_calendars[index].id);
                    setState(() {
                      _selectedCalendar = _calendars[index];
                    });
                  },
                  child: new Padding(
                    padding: const EdgeInsets.all(10.0),
                    child: new Row(
                      children: <Widget>[
                        new Expanded(
                          flex: 1,
                          child: new Text(
                            _calendars[index].name,
                            style: new TextStyle(fontSize: 25.0),
                          ),
                        ),
                        new Icon(_calendars[index].isReadOnly
                            ? Icons.lock
                            : Icons.lock_open)
                      ],
                    ),
                  ),
                );
              },
            ),
          ),
          new Expanded(
            flex: 1,
            child: new Container(
              decoration: new BoxDecoration(color: Colors.white),
              child: new ListView.builder(
                itemCount: _calendarEvents?.length ?? 0,
                itemBuilder: (BuildContext context, int index) {
                  return new EventItem(
                      _calendarEvents[index], _deviceCalendarPlugin, () async {
                    await _retrieveCalendarEvents(_selectedCalendar.id);
                  });
                },
              ),
            ),
          ),
        ],
      ),
      floatingActionButton: !(_selectedCalendar?.isReadOnly ?? true)
          ? new FloatingActionButton(
              onPressed: () async {
                final now = new DateTime.now();
                final eventToCreate = new Event(_selectedCalendar.id);
                eventToCreate.title =
                    "Event created with Device Calendar Plugin";
                eventToCreate.start = now;
                eventToCreate.end = now.add(new Duration(hours: 1));
                final createEventResult = await _deviceCalendarPlugin
                    .createOrUpdateEvent(eventToCreate);
                if (createEventResult.isSuccess &&
                    (createEventResult.data?.isNotEmpty ?? false)) {
                  _retrieveCalendarEvents(_selectedCalendar.id);
                }
              },
              child: new Icon(Icons.add),
            )
          : new Container(),
    );
  }

  void _retrieveCalendars() async {
    try {
      var permissionsGranted = await _deviceCalendarPlugin.hasPermissions();
      if (permissionsGranted.isSuccess && !permissionsGranted.data) {
        permissionsGranted = await _deviceCalendarPlugin.requestPermissions();
        if (!permissionsGranted.isSuccess || !permissionsGranted.data) {
          return;
        }
      }

      final calendarsResult = await _deviceCalendarPlugin.retrieveCalendars();
      setState(() {
        _calendars = calendarsResult?.data;
      });
    } on PlatformException catch (e) {
      print(e);
    }
  }

  Future _retrieveCalendarEvents(String calendarId) async {
    try {
      final startDate = new DateTime.now().add(new Duration(days: -30));
      final endDate = new DateTime.now().add(new Duration(days: 30));
      final retrieveEventsParams =
          new RetrieveEventsParams(startDate: startDate, endDate: endDate);
      final eventsResult = await _deviceCalendarPlugin.retrieveEvents(
          calendarId, retrieveEventsParams);

      setState(() {
        _calendarEvents = eventsResult?.data;
      });
    } catch (e) {
      print(e);
    }
  }
}

class EventItem extends StatelessWidget {
  final Event _calendarEvent;
  final DeviceCalendarPlugin _deviceCalendarPlugin;

  final Function onDeleteSucceeded;

  final double _eventFieldNameWidth = 75.0;

  EventItem(
      this._calendarEvent, this._deviceCalendarPlugin, this.onDeleteSucceeded);

  @override
  Widget build(BuildContext context) {
    return new Card(
      child: new Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          new ListTile(
              title: new Text(_calendarEvent.title ?? ''),
              subtitle: new Text(_calendarEvent.description ?? '')),
          new Container(
            padding: new EdgeInsets.symmetric(horizontal: 16.0),
            child: new Column(
              children: <Widget>[
                new Align(
                  alignment: Alignment.topLeft,
                  child: new Row(
                    children: <Widget>[
                      new Container(
                        width: _eventFieldNameWidth,
                        child: new Text('All day?'),
                      ),
                      new Text(
                          _calendarEvent.allDay != null && _calendarEvent.allDay
                              ? 'Yes'
                              : 'No'),
                    ],
                  ),
                ),
                new SizedBox(
                  height: 10.0,
                ),
                new Align(
                  alignment: Alignment.topLeft,
                  child: new Row(
                    children: <Widget>[
                      new Container(
                        width: _eventFieldNameWidth,
                        child: new Text('Location'),
                      ),
                      new Expanded(
                        child: new Text(
                          _calendarEvent?.location ?? '',
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    ],
                  ),
                ),
                new SizedBox(
                  height: 10.0,
                ),
                new Align(
                  alignment: Alignment.topLeft,
                  child: new Row(
                    children: <Widget>[
                      new Container(
                        width: _eventFieldNameWidth,
                        child: new Text('Attendees'),
                      ),
                      new Expanded(
                        child: new Text(
                          _calendarEvent?.attendees
                                  ?.where((a) => a.name?.isNotEmpty ?? false)
                                  ?.map((a) => a.name)
                                  ?.join(', ') ??
                              '',
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          new ButtonTheme.bar(
            child: new ButtonBar(
              children: <Widget>[
                new IconButton(
                  onPressed: () async {
                    final deleteResult =
                        await _deviceCalendarPlugin.deleteEvent(
                            _calendarEvent.calendarId, _calendarEvent.eventId);
                    if (deleteResult.isSuccess && deleteResult.data) {
                      onDeleteSucceeded();
                    }
                  },
                  icon: new Icon(Icons.delete),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  device_calendar: "^0.0.6"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


      import 'package:device_calendar/device_calendar.dart';
  
Version Uploaded Documentation Archive
0.0.6 Jun 18, 2018 Go to the documentation of device_calendar 0.0.6 Download device_calendar 0.0.6 archive
0.0.5 Jun 14, 2018 Go to the documentation of device_calendar 0.0.5 Download device_calendar 0.0.5 archive
0.0.4 Jun 12, 2018 Go to the documentation of device_calendar 0.0.4 Download device_calendar 0.0.4 archive
0.0.3 Jun 7, 2018 Go to the documentation of device_calendar 0.0.3 Download device_calendar 0.0.3 archive
0.0.2 Jun 7, 2018 Go to the documentation of device_calendar 0.0.2 Download device_calendar 0.0.2 archive
0.0.1 Jun 7, 2018 Go to the documentation of device_calendar 0.0.1 Download device_calendar 0.0.1 archive

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3
  • Flutter: 0.5.4

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
50
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.10
meta 1.1.5
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6 2.0.7
Dev dependencies
flutter_test