Comments (6)
You can use CalendarEventData
class to store event data and you can add it to calendar view using add
method provided by EventController
.
ex.,
// Create event class.
final event = CalendarEventData(
// TODO: Get this data from API.
date: // Start date,
endDate: // End date,
title: // Title,
description: // Description
event: // Optional. Use to store properties that are not provided by CalendarEventData class.
);
// Add event to controller.
controller.add(event);
// Use this if you are using CalendarControllerProvider.
// CalendarControllerProvider.of(context).add(event);
If this is not the answer you are looking for, please provide more info on how you want to show events.
from flutter_calendar_view.
Many thanks for the reply. My doubt was that I have a list of events and I need it to be added to the calendar on their dates, based on what's in the api, with the way you described above can I do this?
from flutter_calendar_view.
Can you please provide one example?
from flutter_calendar_view.
of course, i have this model, and the api gives me a list
import 'dart:convert';
class JobsDescriptionCardsModel {
final String descricaoJob;
final String dataDoJob;
final String horarioDoJob;
JobsDescriptionCardsModel({
required this.descricaoJob,
required this.dataDoJob,
required this.horarioDoJob,
});
Map<String, dynamic> toMap() {
return {
'descricaoJob': descricaoJob,
'dataDoJob': dataDoJob,
'horarioDoJob': horarioDoJob,
};
}
factory JobsDescriptionCardsModel.fromMap(Map<String, dynamic> map) {
return JobsDescriptionCardsModel(
descricaoJob: map['descricao'] ?? "",
dataDoJob: map['data_acao'] ?? "",
horarioDoJob: map['hora_inicial_acao'],",
);
}
String toJson() => json.encode(toMap());
factory JobsDescriptionCardsModel.fromJson(String source) => JobsDescriptionCardsModel.fromMap(json.decode(source));
}
this is the method that does get in the api
@override
Future<List<JobsDescriptionCardsModel>> getJobsDescrition() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
final int? id = sharedPreferences.getInt("idInfluencer");
final String token = sharedPreferences.getString("token") ?? "";
final result = await _restClient.get<List<JobsDescriptionCardsModel>>(
"/job_acoes?influenciador_id=${id.toString()}",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token'
}, decoder: (data) {
if (data != null) {
return data
.map<JobsDescriptionCardsModel>(
(j) => JobsDescriptionCardsModel.fromMap(j))
.toList();
}
return <JobsDescriptionCardsModel>[];
});
if (result.hasError) {
throw ("erro ao buscar dados");
}
return result.body ?? <JobsDescriptionCardsModel>[];
}
and I need to pass this data to the calendar, would it be possible?
from flutter_calendar_view.
Here, I am assuming that you are getting Event date as well from API or somewhere else.
This code snippet should help,
// Get all the jobs
final jobs = await getJobsDescrition();
// Map JobsDescriptionCardsModel to CalendarEventData.
final events = jobs.map((job) => CalendarEventData(
// In CalendarEventData title and date is required.
title: "Title",
date: // Date that you are getting from API/somewhere else.
event: job,
));
// Add events to EventController.
// This is the controller you pass in `CalendarControllerProvider` or as `controller` argument in respected calendar view.
eventController.addAll(events);
from flutter_calendar_view.
great, my friend thank you very much. if not too much abuse do you understand the table calendar? I have a problem displaying my bookmarks there. If you can't help anyway, thank you very much.
from flutter_calendar_view.
Related Issues (20)
- Use theme colors / Support dark mode HOT 1
- Add option to ignore event taps in MonthView
- Auto scroll to the top of the page when i update widget
- Null check exception when adding multiple events without startTime
- Week Day Placement
- The provided ScrollController is currently attached to more than one ScrollPosition.
- Events automatically removed when the view is refreshed or rebuild. using setState or Getx controller HOT 1
- Issue with time duplicate range 00 HOT 1
- Is there a way to stack events and not offset them ? HOT 8
- i18n HOT 3
- Use TimeOfDay instead of DateTime for start and end time in CalendarEventData.
- In dayview, is there a way to set background color for specific hours
- Can i change start time and end time in DayView? HOT 1
- Can the title at the top control hiding and display? HOT 2
- How to add a custom line on the timeline of the network as shown below:
- ScrollController is scrolling parent
- Event tile builder: minimum tile height
- Hide header in Week View HOT 2
- How to add a custom widget at the current time when clicking on onDateTap in the weekly view?
- Weekday border dose not change with monthview show border false HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_calendar_view.