Jamalianpour/time_planner

Time Planner Task Error

Closed this issue · 2 comments

Hi,
I would like to ask regarding the day parameter inside the TimePlannerDateTime inside the TimePlannerTask, is it related to the index for the TimePlannerTitle? Currently, I am facing a problem whereby although the days are different, but there are still displaying only on the first day/first index inside the TimePlannerTitle. I've checked that the data inside each of the lists are correct and the day value inside the task, but there is still no luck to it.

Provider :
getDays() {
List<Map<String, String>> dateMonth = [];
List<Map<String, dynamic>> dateList = [];
DateTime today = DateTime.now();
DateTime firstDay = DateTime(today.year, today.month, 1);
DateTime lastDayOfMonth = DateTime(today.year, today.month + 1, 0);

for (var i = firstDay.day; i <= lastDayOfMonth.day; i++) {
  DateTime currentDate = DateTime(today.year, today.month, i);

  final forecasts = getForecast(currentDate);  --> Function to retrieve the information needed

  forecasts.forEach((element) {
    ForecastPlanningModel forecast = element['forecast'];
    ForecastDetailModel detail = element['details'];
    print(
        "Adding task for ${currentDate.day}-${currentDate.month}-${currentDate.year}");

    task_list.add(TimePlannerTask(
        minutesDuration: 60,
        dateTime: TimePlannerDateTime(
            day: currentDate.day - 1,
            hour: currentDate.hour + i,       
            minutes: currentDate.minute),
        daysDuration: 1,
        child: Wrap(children: [
          Center(
            child: Text(
              "${forecast.farmer} (${detail.subfarm_code ?? ""})",
              style: const TextStyle(
                  color: Colors.red, fontWeight: FontWeight.bold),
            ),
          ),
          Center(child: Text("${detail.forecast}"))
        ])));
  });

  String dayName = _getDayName(currentDate.weekday);
  dateMonth.add({
    'date': "${currentDate.day}-${currentDate.month}-${currentDate.year}",
    'day_name': dayName
  });
}

dateMonth.forEach((e) {
  String day = e['day_name'].toString();
  String date = e['date'].toString();

  TimePlannerTitle(title: day, date: date);

  day_list.add(TimePlannerTitle(title: day, date: date));
});

notifyListeners();

}

String _getDayName(int weekday) {
switch (weekday) {
case 1:
return 'Monday';
case 2:
return 'Tuesday';
case 3:
return 'Wednesday';
case 4:
return 'Thursday';
case 5:
return 'Friday';
case 6:
return 'Saturday';
case 7:
return 'Sunday';
default:
return '';
}
}

Screen :
Provider.of(listen: false, context).day_list;
return value.day_list.isNotEmpty
? Card(
child: SizedBox(
height: 440,
child: TimePlanner(
startHour: 8,
endHour: 23,
use24HourFormat: false,
setTimeOnAxis: false,
style: TimePlannerStyle(
showScrollBar: true,
interstitialEvenColor: Colors.grey[50],
interstitialOddColor: Colors.grey[200],
),
headers: [...day_list],
tasks: [...task_list],
),

Hi, yes, the TimePlannerTitle is an array, therefore, uses the index to assign a task under it. In your case you should declare a new variable and use it as a counter and pass it to the day parameter of TimePlannerDateTime.

dateTime: TimePlannerDateTime(
            day: counter, // add this, remember to increment this on each loop
            hour: currentDate.hour + i,       
            minutes: currentDate.minute),

Thanks for replying and yes, it is able to work now. Hope you have a wonderful day!