I need to parse iCal format in Flutter and I don't find any package for do it. Someone can tell me if it exist any solution for solve my problem?
Asked
Active
Viewed 1,970 times
5
-
Did you get a solution to this? I am likely going to do it in the next couple of weeks but obviously would prefer to save some time. It would be ideal if it could be a Flutter plugin! – brindy Nov 01 '19 at 23:31
-
sorry no solution :/ – Diego MARTINEZ WHITE Nov 20 '19 at 18:48
-
if you find a solution ? – Diego MARTINEZ WHITE Nov 27 '19 at 23:41
-
Not yet, but I am working on an implementation in my spare time. I wouldn't hold your breath though :) – brindy Nov 27 '19 at 23:52
-
@brindy did you release your implementation as open source? – Addell El-haddad Oct 05 '20 at 09:19
-
Nothing worth sharing tbh. I just did something crude as a PoC. The project was supposed to kick off properly in March but got canned because of Covid :( – brindy Oct 05 '20 at 10:56
2 Answers
2
I don't know if you still have your issue but I've just released a package to parse iCalendar format in pure dart.
https://pub.dev/packages/icalendar_parser
It is still in early development stage but might help you with your problem.
Here is an example on how you could use the package:
import 'package:icalendar_parser/icalendar_parser.dart';
// Parsing from an ICS String (ex: if you are getting data from an API)
final iCalParsed = ICalendar.fromString(yourIcsString);
// Parsing from an ICS List<String> (ex: if you are reading data from a file)
final iCalParsed2 = ICalendar.fromLines(icsFileLines);
Here is a full example I've made in Flutter:
import 'dart:core';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:icalendar_parser/icalendar_parser.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
ICalendar _iCalendar;
bool _isLoading = false;
Future<void> _getAssetsFile(String assetName) async {
setState(() => _isLoading = true);
try {
final directory = await getTemporaryDirectory();
final path = p.join(directory.path, assetName);
final data = await rootBundle.load('assets/$assetName');
final bytes =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
final file = await File(path).writeAsBytes(bytes);
final lines = await file.readAsLines();
setState(() {
_iCalendar = ICalendar.fromLines(lines);
_isLoading = false;
});
} catch (e) {
setState(() => _isLoading = false);
throw 'Error: $e';
}
}
Widget _generateTextContent() {
final style = const TextStyle(color: Colors.black);
return RichText(
text: TextSpan(
children: [
TextSpan(
text: 'VERSION: ${_iCalendar.version}\n',
style: style.copyWith(fontWeight: FontWeight.bold)),
TextSpan(
text: 'PRODID: ${_iCalendar.prodid}\n',
style: style.copyWith(fontWeight: FontWeight.bold)),
TextSpan(
children: _iCalendar.data
.map((e) => TextSpan(
children: e.keys
.map((f) => TextSpan(children: [
TextSpan(
text: '${f.toUpperCase()}: ',
style: style.copyWith(
fontWeight: FontWeight.bold)),
TextSpan(text: '${e[f]}\n')
]))
.toList(),
))
.toList()),
],
style: style,
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
children: [
if (_isLoading || _iCalendar == null)
const Center(child: CircularProgressIndicator())
else
_generateTextContent(),
RaisedButton(
child: const Text('Load File 1'),
onPressed: () => _getAssetsFile('calendar.ics'),
),
RaisedButton(
child: const Text('Load File 2'),
onPressed: () => _getAssetsFile('calendar2.ics'),
),
],
),
),
);
}
}

Guillaume Roux
- 6,352
- 1
- 13
- 38
0
To parse/get each platform's calendar?
A quick search of https://pub.dev/packages?q=calendar shows some possible candidates:
- https://pub.dev/packages/add_2_calendar
- https://pub.dev/packages/ical_serializer
- https://pub.dev/packages/device_calendar
- https://pub.dev/packages/manage_calendar_events
Also other related stack posts:
- Adding an event to a calendar from Flutter app, this refers to
device_calendar
plugin - How can I create events in local calendar by Flutter?, this refers to
add_2_calendar
plugin
If you're not satisfied with the existing plugins, then yes, don't hold your breath, but get to work on your own through custom platform-specific code.

TWL
- 6,228
- 29
- 65