add_2_calendar 2.2.1 add_2_calendar: ^2.2.1 copied to clipboard
A really simple Flutter plugin to add events to each platform's default calendar.
import 'package:flutter/material.dart';
import 'package:add_2_calendar/add_2_calendar.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey =
GlobalKey<ScaffoldMessengerState>();
Event buildEvent({Recurrence? recurrence}) {
return Event(
title: 'Test eventeee',
description: 'example',
location: 'Flutter app',
startDate: DateTime.now(),
endDate: DateTime.now().add(Duration(minutes: 30)),
allDay: false,
iosParams: IOSParams(
reminder: Duration(minutes: 40),
url: "http://example.com",
),
androidParams: AndroidParams(
emailInvites: ["test@example.com"],
),
recurrence: recurrence,
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
scaffoldMessengerKey: scaffoldMessengerKey,
home: Scaffold(
appBar: AppBar(
title: const Text('Add event to calendar example'),
),
body: ListView(
// mainAxisAlignment: MainAxisAlignment.center,
children: [
ListTile(
title: Text('Add normal event'),
trailing: Icon(Icons.calendar_today),
onTap: () {
Add2Calendar.addEvent2Cal(
buildEvent(),
);
},
),
Divider(),
ListTile(
title: const Text('Add event with recurrence 1'),
subtitle: const Text("weekly for 3 months"),
trailing: Icon(Icons.calendar_today),
onTap: () {
Add2Calendar.addEvent2Cal(buildEvent(
recurrence: Recurrence(
frequency: Frequency.weekly,
endDate: DateTime.now().add(Duration(days: 60)),
),
));
},
),
Divider(),
ListTile(
title: const Text('Add event with recurrence 2'),
subtitle: const Text("every 2 months for 6 times (1 year)"),
trailing: Icon(Icons.calendar_today),
onTap: () {
Add2Calendar.addEvent2Cal(buildEvent(
recurrence: Recurrence(
frequency: Frequency.monthly,
interval: 2,
ocurrences: 6,
),
));
},
),
Divider(),
ListTile(
title: const Text('Add event with recurrence 3'),
subtitle:
const Text("RRULE (android only) every year for 10 years"),
trailing: Icon(Icons.calendar_today),
onTap: () {
Add2Calendar.addEvent2Cal(buildEvent(
recurrence: Recurrence(
frequency: Frequency.yearly,
rRule: 'FREQ=YEARLY;COUNT=10;WKST=SU',
),
));
},
),
Divider(),
],
),
),
);
}
}