felangel / bloc

A predictable state management library that helps implement the BLoC design pattern
https://bloclibrary.dev
MIT License
11.79k stars 3.39k forks source link

BLoC pattern how to access credentials for the API client? #188

Closed UnnikrishnanBhargavakurup closed 5 years ago

UnnikrishnanBhargavakurup commented 5 years ago

I'm trying BLoC pattern in flutter, I created a repository and API client to access remote REST API in the repository.

I created an instance of the client and the repository in my main function and i'm passing the client as an argument to the repository.

Here my problem is my API client requires some credentials to access the remote server and I'm thinking it should read the credentials from a JSON file. How I can do that?

Also I'm confused from where I should read the JSON file, in the main function or in the API client Also where should I place the JSON file?

Thanks, Unnikrishnan B.

felangel commented 5 years ago

Hi @UnnikrishnanBhargavakurup 👋

Check out this tutorial for how to read/write files. In addition, you might want to consider not going this route and instead, injecting your keys/secrets at build time so that they aren't hard-coded in your source code.