Reputation: 1954
I will display a list of events from Google Calendar. I followed the example already in the following link : How to use Google API in flutter?
and my script is as follows :
import 'package:http/http.dart' as http;
assumed I was logged in.
GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: <String>[
'email',
'https://www.googleapis.com/auth/contacts.readonly',
'https://www.googleapis.com/auth/calendar'
],
);'
class GoogleHttpClient extends http.BaseClient {
Map<String, String> _headers;
GoogleHttpClient(this._headers) : super();
@override
Future<http.StreamedResponse> send(http.BaseRequest request) =>
super.send(request..headers.addAll(_headers)); //have error 'the method 'send' is always abstract in the supertype'
@override
Future<http.Response> head(Object url, {Map<String, String> headers}) =>
super.head(url, headers: headers..addAll(_headers));
}
void getCalendarEvents() async {
final authHeaders = _googleSignIn.currentUser.authHeaders;
final httpClient = new GoogleHttpClient(authHeaders); //have error "The argument type 'Future<Map<String, String>>' can't be assigned to the parameter type 'Map<String, String>'"
var calendar = new Calendar.CalendarApi(new http.Client());
var calEvents = calendar.events.list("primary");
calEvents.then((Calendar.Events events) {
events.items.forEach((Calendar.Event event) {print(event.summary);});
});
}
the above script cannot run because of an error.
the method 'send' is always abstract in the supertype
can someone help me?
Upvotes: 0
Views: 768
Reputation: 120
Replace StreamedResponse with IOStreamedResponse
add IOClient library
replace class GoogleHttpClient extends IOClient
with class GoogleHttpClient extends http.BaseClient
Upvotes: 1
Reputation: 2032
1 This is error
//have error "The argument type 'Future<Map<String, String>>' can't be assigned to the parameter type 'Map<String, String>'"
fixed: add await ahead
Like below:
final authHeaders = await _googleSignIn.currentUser.authHeaders;
2: Change like below
var calendar = new Calendar.CalendarApi(new http.Client());
to
var calendar = new Calendar.CalendarApi(httpClient);
======> Final:
void getCalendarEvents() async {
final authHeaders = await _googleSignIn.currentUser.authHeaders;
final httpClient = new GoogleHttpClient(authHeaders);
var calendar = new Calendar.CalendarApi(httpClient);
var calEvents = calendar.events.list("primary");
calEvents.then((Calendar.Events events) {
events.items.forEach((Calendar.Event event) {print(event.summary);});
});
}
It worked for me.
Upvotes: 0
Reputation: 657871
If your code is based on How to use Google API in flutter? you'll see that I have a @override Future<StreamedResponse> send(...)
in my code.
GoogleHttpClient
extends abstract class IOClient
that is missing an implementation of send
, so the concrete subclass needs to implement it.
That's what the error message is about.
Upvotes: 1