This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
LocalSpend-Tracker/lib/common/apifunctions/request_logout_api.dart
Felix fef1621d3e
Logout works
all that needs doing now is 'save login'
2019-07-16 11:42:34 +01:00

39 lines
881 B
Dart

import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:local_spend/common/functions/get_token.dart';
import 'package:local_spend/common/functions/save_logout.dart';
import 'package:local_spend/model/json/login_model.dart';
Future<LoginModel> requestLogoutAPI(BuildContext context) async {
final url = "https://dev.peartrade.org/api/logout";
var token;
await getToken().then((result) {
token = result;
});
Map<String, String> body = {
"Token":token,
};
final response = await http.post(
url,
body: json.encode(body),
);
if (response.statusCode == 200) {
debugPrint("Logout successful: " + response.body);
saveLogout();
return null;
} else {
debugPrint("Logout unsuccessful: " + response.body);
saveLogout();
return null;
}
}