'Using token authentication with flutter swagger_dart_code_generator

I'm currently learning flutter and how to develop mobile apps with a server backend. I've came across the library swagger_dart_code_generator, which generates Dart Models and API functions based on a swagger file. I have followed the example they have and I managed to get myself a basic working REST Application. So my request to api.userLogin(); returns a JWTToken as expected.

The next step was figuring out, how to send a JWTToken with requests that require authentication, but I found no examples in their GitHub repository, nor did I see a Member Function in the generated code, that lets me set headers to the HTTP request. What I am basically trying to do, is to send the JWTToken I already got to a function like api.getSuperSecretUserInfo(); and get a response from the Server other than a "401 Unautherized".



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source