Skip to content

[Calendar] TypeErrorImpl thrown by gesture when clicking on appointment in monthview #39

Closed

Description

@solvaer

Flutter Calendar throws a TypeErrorImpl exception when clicking on appointment in monthview with custom appointments.
Using Flutter Web on beta channel and syncfusion_flutter_calendar: ^18.3.44

════════ Exception caught by gesture ═══════════════════════════════════════════
The following TypeErrorImpl was thrown while handling a gesture:
Expected a value of type 'Appointment', but got one of type 'Meeting'

When the exception was thrown, this was the stack
dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 216:49 throw
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 64:3 castError
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 442:10 cast
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart 420:9 as
packages/syncfusion_flutter_calendar/src/calendar/views/calendar_view.dart 1411:59 [_handleTouchOnMonthView]
...
Handler: "onTapUp"
Recognizer: TapGestureRecognizer#148a5
debugOwner: GestureDetector
state: ready
won arena
finalPosition: Offset(142.0, 163.0)
finalLocalPosition: Offset(137.0, 67.0)
button: 1
sent tap down
════════════════════════════════════════════════════════════════════════════════

Source:
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';

class CalendarScreen extends StatefulWidget {
const CalendarScreen({Key key}) : super(key: key);
@OverRide
_CalendarScreenState createState() => _CalendarScreenState();
}

MeetingDataSource _events;

class _CalendarScreenState extends State {
CalendarView _calendarView;
List appointments;

@OverRide
void initState() {
_calendarView = CalendarView.month;
appointments = getMeetingDetails();
_events = MeetingDataSource(appointments);
super.initState();
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Calendar'),
),
body: Padding(
padding: const EdgeInsets.fromLTRB(5, 0, 5, 5),
child: getEventCalendar(_calendarView, _events, onCalendarTapped)));
}

SfCalendar getEventCalendar(
[CalendarView _calendarView,
CalendarDataSource _calendarDataSource,
CalendarTapCallback calendarTapCallback]) {
return SfCalendar(
allowViewNavigation: true,
view: _calendarView,
allowedViews: [
CalendarView.day,
CalendarView.week,
CalendarView.month,
CalendarView.schedule,
],
dataSource: _calendarDataSource,
onTap: calendarTapCallback,
initialDisplayDate: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, 0, 0, 0),
monthViewSettings: MonthViewSettings(
appointmentDisplayMode: MonthAppointmentDisplayMode.appointment,
),
);
}

void onCalendarViewChange(String value) {
if (value == 'Day') {
_calendarView = CalendarView.day;
} else if (value == 'Week') {
_calendarView = CalendarView.week;
} else if (value == 'Work week') {
_calendarView = CalendarView.workWeek;
} else if (value == 'Month') {
_calendarView = CalendarView.month;
}
}

void onCalendarTapped(CalendarTapDetails details) {
if (details.targetElement != CalendarElement.calendarCell) {
return;
}
if (_calendarView == CalendarView.month) {
setState(() {
_calendarView = CalendarView.day;
});
}
}
}

List getMeetingDetails() {
final List _meetings = [];
_meetings.add(Meeting(
from: DateTime.now(),
to: DateTime.now().add(const Duration(hours: 1)),
eventName: "Test Meeting",
background: Colors.grey,
isAllDay: false,
));

return _meetings;
}

class Meeting {
Meeting({
this.eventName,
@required this.from,
@required this.to,
this.background,
this.isAllDay,
});

final String eventName;
final DateTime from;
final DateTime to;
final Color background;
final bool isAllDay;
}

class MeetingDataSource extends CalendarDataSource {
MeetingDataSource(List source) {
appointments = source;
}

@OverRide
DateTime getStartTime(int index) => appointments[index].from;

@OverRide
DateTime getEndTime(int index) => appointments[index].to;

@OverRide
String getSubject(int index) => appointments[index].eventName;

@OverRide
Color getColor(int index) => appointments[index].background;

@OverRide
bool isAllDay(int index) => appointments[index].isAllDay;
}

Activity

  1. Indumathi1195R commented on Nov 3, 2020

    @Indumathi1195R

    Hi,

    Based on the provided information, we have checked the mentioned exception “Exception thrown when clicking custom appointment” from our end. Due to appointment type conversion, the mentioned exception was thrown while tapping the custom appointments on month cell. We suspect that you have set the custom appointment details to normal appointments. So, kindly set the appointment details to the corresponding appointment type. Kindly refer the following code snippet for the same.

    Code snippet:

    void calendarTapped(CalendarTapDetails details) {
      if (details.targetElement == CalendarElement.appointment) {
        final Meeting appointmentDetails = details.appointments[0];
      }
    }
    
    

    We hope that this helps you. Please let us know if you need further assistance.

    Regards,
    Indumathi R

  2. solvaer commented on Nov 3, 2020

    @solvaer
    Author

    Hi,

    Thank you for the info. Currently I am not doing any conversion in the calendarTapped handler, merely catching a cell click. This works correctly in all views but not in the Month view when you click on the appointment.

    I also tried an empty calendarTapped handler, still throws exception when you click on the appointment in the month view, not in other views.

    I also copied your provided calendarTapped handler verbatim and same behavior: It works correctly in all views, but not in the Month view.

    Regards,
    Erik

  3. Indumathi1195R commented on Nov 5, 2020

    @Indumathi1195R

    Hi,

    We have already found and fixed the mentioned issue “Exception thrown when clicking custom appointment in the month view of the Flutter calendar”. We will include the issue fix in our upcoming Weekly Nuget package, which is expected to roll out by November 10, 2020. We appreciate your patience until then.

    Regards,
    Indumathi R

  4. Indumathi1195R commented on Nov 11, 2020

    @Indumathi1195R

    Hi,

    We have included the issue fix for “Exception thrown when clicking custom appointment in the month view of the Flutter calendar”. Kindly update to the latest Weekly Nuget package version 18.3.48 for resolving this issue. Also please find the latest version from the below pub document link.

    Pub link:
    https://pub.dev/packages/syncfusion_flutter_calendar/versions

    Regards,
    Indumathi R

  5. solvaer commented on Nov 13, 2020

    @solvaer
    Author

    Thank you, I appreciate it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions