Впервые на флаттер. У меня эта кнопка и при нажатии запускает календарь на устройстве. Я хочу сделать эту кнопку динамической c, так как в моем списке model / events.dart у меня более 20 дат, и я хочу запустить календарь с указанной c датой, например DateTime ('$ {events.date}' ) может быть? Есть ли другое решение для этого? Ошибки Vs Code говорят мне, что я должен создать геттер, чтобы решить эту проблему. Мысли?
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",
);