How to make a dynamic Flutter button with add2calendar package?
741
You can use a List<Events>
:
In your events.dart
final events = [
ponteRagogna,
new Events(...)
];
In your code :
Row(
children: [
for (var staticEvent in events)
IconButton(
onPressed: () {
final event = Event(
title: '',
description: '',
location: '',
startDate: DateTime(staticEvent.date),
endDate: DateTime(staticEvent.date),
allDay: false,
);
Add2Calendar.addEvent2Cal(event)
},
)
]
)
Author by
blueprint
Updated on December 18, 2022Comments
-
blueprint over 1 year
New to Flutter. I have this button and on pressed is launching the calendar on device. I want to make this button dynamic as i have more than 20 dates in my model/events.dart list and i want to launch the calendar with the specific date like DateTime('${events.date}') maybe? Is there another solution for this? Vs Code errors is telling me that i should create a getter to solve this. Thoughts?
import 'package:flutter/material.dart'; import 'package:add_2_calendar/add_2_calendar.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; import '../model/events.dart'; class Calendar extends StatefulWidget { @override _CalendarState createState() => _CalendarState(); } class _CalendarState extends State<Calendar> { final GlobalKey<ScaffoldState> scaffoldState = GlobalKey(); @override Widget build(BuildContext context) { Event event = Event( title: '', description: '', location: '', startDate: DateTime.now(), endDate: DateTime.now(), allDay: false, ); return Row( children: <Widget>[ IconButton( icon: Icon( FontAwesomeIcons.calendarAlt, size: 30.0, color: Colors.green, ), onPressed: () { Add2Calendar.addEvent2Cal(event); }, ), ], ); } }
import 'package:flutter/foundation.dart'; class Events { final String imagePath, title, description, location, duration, punchLine1, punchLine2, address, shareB, phone, fb, maps, guide, date; final List categoryIds, galleryImages; Events({ @required this.imagePath, @required this.title, @required this.description, @required this.location, @required this.duration, @required this.punchLine1, @required this.punchLine2, @required this.categoryIds, @required this.galleryImages, @required this.address, @required this.shareB, @required this.phone, @required this.fb, @required this.maps, @required this.guide, @required this.date, }); } final ponteRagogna = Events( imagePath: "assets/locations/ponte1.jpg", title: "Osteria al Ponte dal Lupo", description: "", location: "Ragogna", duration: "", punchLine1: "Osteria", punchLine2: " al Ponte dal Lupo", address: "Via al Ponte 6, Ragogna", maps: "46.184476,12.96572912", phone: "+393501073003", fb: "https://www.facebook.com/pages/category/Restaurant/Osteria-al-ponte-dal-lupo-2354276691519510/", galleryImages: [ "assets/locations/ponte0.jpg", "assets/locations/ponte1.jpg", "assets/locations/ponte2.jpg", ], categoryIds: [ 2, ], shareB: "https://www.tripadvisor.it/Restaurant_Review-g666616-d3964038-Reviews-Osteria_al_Ponte-Cison_Di_Valmarino_Province_of_Treviso_Veneto.html", guide: "", date: "24-09-2020", );
-
Augustin R about 4 yearsCan you please share a sample of
events.dart
? -
blueprint about 4 yearsI've just posted my events.dart file, i just can't find a way to make date dynamic here
-
Augustin R about 4 yearsHave you tried
DateTime(ponteRagogna.date)
? -
blueprint about 4 yearsThanks for the answer but I have around 20 events with different dates and i need something like "startDate: DateTime('${events.date}')" from the provider
-
Augustin R about 4 yearsI added an answer in the case you want one button per event.
-
Augustin R about 4 yearsIs there a significant difference between
Event
class andEvents
? -
blueprint about 4 yearsstill not working, event class is used by add2calendar and i had to modify mine in events
-
-
Sagar Acharya over 2 yearsIs there any way we can add multiple events at once for this package, Or any other plugin that you might have gone through