Skip to content

Instantly share code, notes, and snippets.

@yusufbiberoglu
Created January 23, 2023 13:14
Show Gist options
  • Save yusufbiberoglu/f9b707a36acca2ef7b99ea2a61031859 to your computer and use it in GitHub Desktop.
Save yusufbiberoglu/f9b707a36acca2ef7b99ea2a61031859 to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Api {
token() async {
SharedPreferences localStorage = await SharedPreferences.getInstance();
var token = localStorage.getString('token');
return '?token=$token';
}
login(data) async {
var fullUrl = 'http://127.0.0.1:8000/authentication' + await token();
Response response = await http.post(
Uri.parse(fullUrl),
body: jsonEncode(data),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment