Giter Site home page Giter Site logo

Comments (6)

PRBaraiya avatar PRBaraiya commented on June 11, 2024

Hi @Flavio-Vieirastack,

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.

Flavio-Vieirastack avatar Flavio-Vieirastack commented on June 11, 2024

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.

PRBaraiya avatar PRBaraiya commented on June 11, 2024

Can you please provide one example?

from flutter_calendar_view.

Flavio-Vieirastack avatar Flavio-Vieirastack commented on June 11, 2024

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.

PRBaraiya avatar PRBaraiya commented on June 11, 2024

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.

Flavio-Vieirastack avatar Flavio-Vieirastack commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.