After 1 day of research. I made it as follows
Import libs
date_utils: ^0.1.0+3
googleapis_auth: ^0.2.11+1
googleapis: ^0.54.0
Code
final GoogleSignIn _googleSignIn =
GoogleSignIn(
scopes: <String>[
CalendarApi.CalendarScope,
],
)
signInWithGoogle() async {
await _googleSignIn.signIn();
final headers = await _googleSignIn.currentUser.authHeaders;
getEvent(headers);
}
getEvent(headers) async {
final httpClient = GoogleHttpClient(headers);
var calendar = CalendarApi(httpClient);
DateTime lastMonth = Utils.lastDayOfMonth(DateTime.now());
DateTime firstMonth = Utils.firstDayOfMonth(DateTime.now());
var calEvents = calendar.events.list("primary", timeMax: lastMonth.toUtc(), timeMin: firstMonth.toUtc());
calEvents.then(
(events) => {events.items.forEach((event) => print("EVENT ${event.summary}"))});
}
This is GoogleHttpClient.class
import 'package:http/io_client.dart';
import 'package:http/http.dart';
class GoogleHttpClient extends IOClient {
Map<String, String> _headers;
GoogleHttpClient(this._headers) : super();
@override
Future<StreamedResponse> send(BaseRequest request) =>
super.send(request..headers.addAll(_headers));
@override
Future<Response> head(Object url, {Map<String, String> headers}) =>
super.head(url, headers: headers..addAll(_headers));
}
Hope it helpful