add_to_calendar 1.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

add_to_calendar #

pub package

Flutter plugin that allows opening a native UI to add an event with custom parameters to user's calendar

Installation #

Declare a pubspec dependency in your Flutter project.

In iOS #

Add NSCalendarsUsageDescription String entry in your info.plist explaining why you require calendar access permissions.

What is it for? #

It allows developers

How to use it? #

You can check the Example app to see a real use case on how to trigger the native view to add custom events to user's calendar. Snippet of the main function of the plugin:

  /// Function responsible of triggering the native view to create a custom event in user's calendar using given parameters
  /// 
  /// [title] is String value of the title to be filled
  /// [startTime] DateTime with the start time of the event
  /// [endTime] DateTime with the end time of the event. Optional if [isAllDay] is true, required otherwise.
  /// [isAllDay] bool value stating if the event will be a full day event
  /// [location] optional String with the location of the event
  /// [description] optional String with the description of the event
  /// [frequency] optional int with the information about recurrence of the event
  /// [frequencyType] optional enum that states the frequency. Daily, weekly, monthly
  /// 
  static Future addToCalendar({
    @required String title,
    @required DateTime startTime,
    DateTime endTime,
    bool isAllDay = false,
    String location,
    String description,
    int frequency,
    FrequencyType frequencyType,
  })

1.2.0 #

  • Add support to create recurrence events

1.1.0 #

  • When setting event as same day, use start date value as end time as well

1.0.1 #

  • Cleanup non needed dependencies

1.0.0 #

  • Fix crash on Android when parsing dates

0.0.2+2 #

  • Fix not matching meta version with flutter so documentation can be generated

0.0.2+1 #

  • Upgrade gradle plugins in android

0.0.2 #

  • Fix maintenance issues reported in pub.dev

0.0.1 #

  • Allow to trigger a mechanism (Intent in android and EventStore in iOS) to open a native component to add events into user's calendar

example/lib/main.dart

import 'package:add_to_calendar/add_to_calendar.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: _Home());
  }
}

class _Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<_Home> {
  String title = '';
  String location = '';
  String description = '';
  int frequency;
  FrequencyType selectedFrequency;
  DateTime startDate;
  DateTime endDate;
  TextEditingController endDateController = TextEditingController();
  bool allDay = false;

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Add to calendar Plugin Demo'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(24.0),
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                TextField(
                  decoration: const InputDecoration(
                    labelText: 'Event title:',
                  ),
                  onChanged: (String value) => setState(() {
                    title = value;
                  }),
                ),
                TextField(
                  decoration: const InputDecoration(
                    labelText: 'Event description: (Optional)',
                  ),
                  onChanged: (String value) => setState(() {
                    description = value;
                  }),
                ),
                TextField(
                  decoration: const InputDecoration(
                    labelText: 'Event location: (Optional)',
                  ),
                  onChanged: (String value) => setState(() {
                    location = value;
                  }),
                ),
                SizedBox(height: 8),
                GestureDetector(
                  onTap: () async {
                    final DateTime picked = await showDatePicker(
                      context: context,
                      initialDate: DateTime.now(),
                      firstDate: DateTime(2015, 8),
                      lastDate: DateTime(2101),
                    );
                    if (picked != null && picked != startDate)
                      setState(() {
                        startDate = picked;
                      });
                  },
                  child: Text(startDate != null ? startDate.toIso8601String() : 'Select start date'),
                ),
                SizedBox(height: 8),
                GestureDetector(
                  onTap: () async {
                    final DateTime picked = await showDatePicker(
                      context: context,
                      initialDate: DateTime.now(),
                      firstDate: DateTime(2015, 8),
                      lastDate: DateTime(2101),
                    );
                    if (picked != null && picked != endDate)
                      setState(() {
                        endDate = picked;
                      });
                  },
                  child: Text(endDate != null ? endDate.toIso8601String() : 'Select end date'),
                ),
                TextField(
                  decoration: const InputDecoration(
                    labelText: 'Frequency: (Optional)',
                  ),
                  keyboardType: TextInputType.number,
                  onChanged: (String value) => setState(() {
                    frequency = int.parse(value);
                  }),
                ),
                SizedBox(height: 8),
                Row(
                  children: [
                    Text('All day'),
                    Checkbox(
                      value: allDay,
                      onChanged: (checked) {
                        setState(() {
                          endDate = null;
                          endDateController.clear();
                          allDay = checked;
                        });
                      },
                    ),
                  ],
                ),
                SizedBox(height: 8),
                DropdownButton<FrequencyType>(
                  hint: Text("Select frequency"),
                  value: selectedFrequency,
                  onChanged: (value) {
                    setState(() {
                      selectedFrequency = value;
                    });
                  },
                  items: FrequencyType.values.map((frequencyType) {
                    return DropdownMenuItem<FrequencyType>(
                      value: frequencyType,
                      child: Text(frequencyType.toString()),
                    );
                  }).toList(),
                ),
                SizedBox(height: 8),
                RaisedButton(
                  child: const Text('Add to calendar'),
                  onPressed: title.isEmpty || startDate == null
                      ? null
                      : () {
                          return AddToCalendar.addToCalendar(
                            title: title,
                            startTime: startDate,
                            endTime: endDate,
                            location: location,
                            description: description,
                            isAllDay: allDay,
                            frequency: frequency,
                            frequencyType: selectedFrequency,
                          );
                        },
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  add_to_calendar: ^1.2.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


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

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/add_to_calendar.dart.

Run flutter format to format lib/add_to_calendar.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
meta ^1.1.6 1.1.8
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
matcher ^0.12.5
mockito ^4.1.0
test ^1.6.3