Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding static http headers #678

Open
karthiga812 opened this issue Jun 5, 2024 · 1 comment
Open

Adding static http headers #678

karthiga812 opened this issue Jun 5, 2024 · 1 comment

Comments

@karthiga812
Copy link

Describe the bug
I'm trying to add static http headers to my API call like in the example.
@headers(<String, dynamic>{
'Content-Type': 'application/json',
'Custom-Header': 'Your header',
})
But I'm getting an error 'Annotation must be either a const variable reference or const constructor invocation.'
Can someone help?

Steps to reproduce the behavior:
Add static http headers to any API call like below,
@get('/api/endpoint')
@headers(<String, dynamic>{
'Content-Type': 'application/json',
'Custom-Header': 'Your header',
})

Expected behavior
The headers must be added to the API request and should get success response.

@geusan
Copy link

geusan commented Sep 12, 2024

I've got same issue but i solved.

import 'package:retrofit/http.dart' as http;

@http.Headers({"Content-Type": "application/json"})

It is working.
I think there is same naming issue with dio package's Headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants