Hi, I made this widget to create events inside device default calendar, you can set icon, color, interval, ocurrency. There you have it, hope this will be useful:
Is just an button icon, but you can add all the details to pass data to your device calendar, also you can use it dinamically in listview or gridview.
Note, the parameter called "mattress" you can named it as you like
This is how it will look like in Custom Widgets tab:
Add the parameters
CODE:
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class AddToCalendarButton extends StatefulWidget {
const AddToCalendarButton({
Key? key,
this.width,
this.height,
required this.nextDateTime,
required this.mattress,
required this.myIcon,
required this.myColor,
required this.ocurrences,
required this.interval,
}) : super(key: key);
final double? width;
final double? height;
final DateTime nextDateTime;
final String mattress;
final Widget? myIcon;
final Color? myColor;
final int ocurrences;
final int interval;
@override
AddToCalendarButtonState createState() => AddToCalendarButtonState();
}
final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey =
GlobalKey<ScaffoldMessengerState>();
Event buildEvent(
{Recurrence? recurrence, required DateTime dt, required String mattress}) {
return Event(
title: 'La Repa',
description: 'Hora de rotar el colchón ${mattress}',
location: 'La Repa app',
startDate: dt,
endDate: dt.add(Duration(minutes: 30)),
allDay: false,
recurrence: recurrence,
);
}
class AddToCalendarButtonState extends State<AddToCalendarButton> {
@override
Widget build(BuildContext context) {
return IconButton(
icon: new Icon(Icons.calendarmonth_outlined),
color: widget.myColor,
onPressed: () {
Add2Calendar.addEvent2Cal(buildEvent(
recurrence: Recurrence(
frequency: Frequency.monthly,
interval: widget.interval,
ocurrences: widget.ocurrences,
),
dt: widget.nextDateTime,
mattress: widget.mattress));
},
);
}
}