Last active
September 26, 2018 06:01
-
-
Save mirajehossain/87674592c8fa4bea2843593d7694269a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:http/http.dart' as http; | |
import 'dart:convert'; | |
import 'package:flutter_sqflite_app/model/user.model.dart'; | |
class ApiService { | |
static final BASE_URL = "https://xxxxxxxx.herokuapp.com"; | |
static final LOGIN_URL = BASE_URL + "/auth/v1/users/login"; | |
Future<UserModel> login(String email, String password) async { | |
try { | |
final response = await http.post(LOGIN_URL, body: { | |
"email": email, | |
"password": password | |
}); | |
print('response: -' + json.decode(response.body)); | |
final user = UserModel.fromJson(json.decode(response.body)); | |
print('status: '); | |
print(user.message); | |
if (user.status) { | |
print('print from service: $user'); | |
return user; | |
} else { | |
print('print error from service: $user'); | |
throw (user.message); | |
} | |
} catch (e) { | |
print('print err, from service: $e'); | |
throw (e.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment