I am trying to create a course in Google Classroom from an app in Fluter. I am trying to make a button, when clicking, execute a method, in which the necessary values are already loaded, but it gives me the following error:
DartError: Unsupported operation: ServerSocket.bind
Everything that follows is the code
imports:
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:oxxyweb/Functions/global/gloals.dart' as globals;
import 'package:intl/intl.dart';
import 'package:googleapis/classroom/v1.dart';
import 'package:googleapis_auth/auth_io.dart';
method:
Future<void> createCourse() async {
// Autenticación
final clientId = ClientId('id', 'secret');
final scopes = [ClassroomApi.classroomCoursesScope];
// Obtiene el cliente autenticado
var client = await clientViaUserConsent(clientId, scopes, (url) {
print("Por favor, ve a $url e ingresa el código");
});
var classroomApi = ClassroomApi(client);
// Crea un nuevo curso
var course = Course()
..name = "Nombre del Curso"
..section = "Sección"
..descriptionHeading = "Descripción del curso"
..description = "Descripción detallada"
..room = "Aula"
..ownerId = "[email protected]"; // El ID del propietario
try {
var createdCourse = await classroomApi.courses.create(course);
print('Curso creado con ID: ${createdCourse.id}');
} catch (e) {
print('Error al crear el curso: $e');
} finally {
client.close();
}
}
button:
ElevatedButton(
onPressed: () {
createCourse();
},
child: Text('Crear Curso'),
),
I am using Google Chrome since I am testing from a web app, I have already enabled the Classroom API in Google Cloud, and I have been researching the information that Google gives, but I have not found a solution.