Skip to content

Instantly share code, notes, and snippets.

@ptruiz
Created October 12, 2020 22:39
Show Gist options
  • Save ptruiz/df95588bfa637ef67b007f8776e7d7a0 to your computer and use it in GitHub Desktop.
Save ptruiz/df95588bfa637ef67b007f8776e7d7a0 to your computer and use it in GitHub Desktop.
void loginWithGitHub(String code) async {
//Step 4
final response = await http.post(
"https://github.com/login/oauth/access_token",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: "{\"client_id\":\"" + CLIENT_ID
+ "\",\"client_secret\":\"" + CLIENT_SECRET
+ "\",\"code\":\"" + code
+ "\"}",
);
@MrCsabaToth
Copy link

In the body interpolation the dart string can be single quote string, so you wouldn't have to escape the quotes inside the string everywhere => it'd make the code more readable. (Unless you are using some automatic styling plugin which strictly enforcing the double quotes.)
I'd also use string interpolation for the variables:

body: '{"client_id":$CLIENT_ID",' + 
        + '"client_secret":"$CLIENT_SECRET",' + 
        + '"code":"$code"}',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment