Skip to content

Instantly share code, notes, and snippets.

@mirajehossain
Last active September 26, 2018 06:01
Show Gist options
  • Save mirajehossain/87674592c8fa4bea2843593d7694269a to your computer and use it in GitHub Desktop.
Save mirajehossain/87674592c8fa4bea2843593d7694269a to your computer and use it in GitHub Desktop.
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