zet_in_agenda.dart 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Automatic FlutterFlow imports
  2. import '/backend/schema/structs/index.dart';
  3. import '/flutter_flow/flutter_flow_theme.dart';
  4. import '/flutter_flow/flutter_flow_util.dart';
  5. import 'index.dart'; // Imports other custom actions
  6. import '/flutter_flow/custom_functions.dart'; // Imports custom functions
  7. import 'package:flutter/material.dart';
  8. // Begin custom action code
  9. // DO NOT REMOVE OR MODIFY THE CODE ABOVE!
  10. // Set your action name, define your arguments and return parameter,
  11. // and then add the boilerplate code using the `</>` button on the right!
  12. import 'package:add_2_calendar/add_2_calendar.dart';
  13. Future<bool> zetInAgenda(String titel, String startIso, String? eindIso,
  14. String? locatie, String? omschrijving, String? plaats, String? nid) async {
  15. DateTime? start = DateTime.tryParse(startIso.trim().replaceFirst(' ', 'T'));
  16. if (start == null) {
  17. return false;
  18. }
  19. DateTime? eind;
  20. if (eindIso != null && eindIso.trim().isNotEmpty) {
  21. eind = DateTime.tryParse(eindIso.trim().replaceFirst(' ', 'T'));
  22. }
  23. if (eind == null || !eind.isAfter(start)) {
  24. eind = start.add(Duration(hours: 2));
  25. }
  26. String tekst = omschrijving ?? '';
  27. tekst = tekst.replaceAll(RegExp(r'<[^>]*>'), ' ');
  28. tekst = tekst.replaceAll('&nbsp;', ' ');
  29. tekst = tekst.replaceAll('&amp;', '&');
  30. tekst = tekst.replaceAll(RegExp(r'\s+'), ' ').trim();
  31. if (tekst.length > 500) {
  32. tekst = tekst.substring(0, 500) + '...';
  33. }
  34. String naam = titel.trim();
  35. if (naam.isEmpty) {
  36. naam = 'Evenement';
  37. }
  38. String link = (nid ?? '').trim();
  39. if (link.isNotEmpty) {
  40. tekst = 'https://uitgk.com/' + link + '\n\n' + tekst;
  41. }
  42. eind = start;
  43. if ((locatie ?? '').trim().isEmpty) {
  44. locatie = (plaats ?? '').trim();
  45. } else if ((plaats ?? '').trim().isNotEmpty) {
  46. locatie = (locatie ?? '').trim() + ', ' + (plaats ?? '').trim();
  47. }
  48. try {
  49. return await Add2Calendar.addEvent2Cal(Event(
  50. title: naam,
  51. description: tekst,
  52. location: (locatie ?? '').trim(),
  53. startDate: start,
  54. endDate: eind));
  55. } catch (e) {
  56. return false;
  57. }
  58. }