Flutter web application fails to integrate with Google Calendar API

I’m working on a Flutter project where I need to sync events with Google Calendar using their API. The app should let users add events directly to their Google calendar.

The problem is that when I test the functionality, nothing happens at all. The authentication flow doesn’t even start and I never see the permission request. When debugging, the execution seems to stop at the authentication step without any error messages.

Here’s my implementation:

class GoogleCalendarService {
  static const _permissions = [CalendarApi.calendarScope];
    
  addEvent(eventTitle, date, beginTime, finishTime) {
    var authClient;

    if (kIsWeb) {
      authClient = ClientId("<web-client-id>.apps.googleusercontent.com","");
    } else {
      authClient = ClientId("<android-client-id>.apps.googleusercontent.com","");
    }

    clientViaUserConsent(authClient, _permissions, handleAuth).then((AuthClient client) {
      var calendarService = CalendarApi(client);
      calendarService.calendarList
          .list()
          .then((result) => debugPrint("RESULT: $result"));

      String targetCalendar = "primary";
      Event newEvent = Event();

      newEvent.summary = eventTitle;

      EventDateTime eventStart = EventDateTime();
      eventStart.dateTime = beginTime;
      eventStart.timeZone = "GMT+05:00";
      newEvent.start = eventStart;

      EventDateTime eventFinish = EventDateTime();
      eventFinish.timeZone = "GMT+05:00";
      eventFinish.dateTime = finishTime;
      newEvent.end = eventFinish;
      
      try {
        calendarService.events.insert(newEvent, targetCalendar).then((result) {
          debugPrint("STATUS: ${result.status}");
          if (result.status == "confirmed") {
            log('Successfully created calendar event');
          } else {
            log("Failed to create calendar event");
          }
        });
      } catch (error) {
        log('Exception occurred: $error');
      }
    });
  }

  void handleAuth(String authUrl) async {
    debugPrint("Navigate to this URL for authorization:");
    debugPrint("  => $authUrl");

    if (await canLaunchUrl(authUrl as Uri)) {
      await launchUrl(authUrl as Uri);
    } else {
      throw 'Cannot open $authUrl';
    }
  }
}

I’ve tested this on Chrome and Android but both platforms have the same issue. The authentication callback never triggers and the code execution halts at the clientViaUserConsent call without any visible errors.

Any ideas what might be causing this issue?