From 96fdc01eea322f685f3e81979973901d4fbaea33 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 27 Aug 2019 12:18:02 +0100 Subject: [PATCH] logout works properly --- .../apifunctions/request_logout_api.dart | 20 +++++-------------- lib/common/functions/logout.dart | 11 +++++----- lib/common/functions/save_logout.dart | 2 -- lib/pages/receipt_page_2.dart | 4 ++-- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/lib/common/apifunctions/request_logout_api.dart b/lib/common/apifunctions/request_logout_api.dart index efb64a3..471ce9f 100644 --- a/lib/common/apifunctions/request_logout_api.dart +++ b/lib/common/apifunctions/request_logout_api.dart @@ -1,13 +1,13 @@ 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 requestLogoutAPI(BuildContext context) async { +Future requestLogoutAPI() async { + saveLogout(); + final url = "https://dev.localspend.co.uk/api/logout"; var token; @@ -20,20 +20,10 @@ Future requestLogoutAPI(BuildContext context) async { "Token": token, }; - final response = await http.post( + 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; - } + return true; } diff --git a/lib/common/functions/logout.dart b/lib/common/functions/logout.dart index 68e47a1..1b14d6b 100644 --- a/lib/common/functions/logout.dart +++ b/lib/common/functions/logout.dart @@ -1,17 +1,18 @@ import 'package:flutter/material.dart'; import 'package:local_spend/common/apifunctions/request_logout_api.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:local_spend/common/functions/save_logout.dart'; void logout(context) { - requestLogoutAPI(context); - Navigator.of(context).pushReplacementNamed('/LoginPage'); - _clearLoginDetails(); + _clearLoginDetails().then((_) { + requestLogoutAPI(); + Navigator.of(context).pushReplacementNamed('/LoginPage'); + }); } -void _clearLoginDetails() async { +Future _clearLoginDetails() async { SharedPreferences preferences = await SharedPreferences.getInstance(); await preferences.setString('username', ""); await preferences.setString('password', ""); - print("details cleared"); } diff --git a/lib/common/functions/save_logout.dart b/lib/common/functions/save_logout.dart index 92753cb..4d5e419 100644 --- a/lib/common/functions/save_logout.dart +++ b/lib/common/functions/save_logout.dart @@ -6,6 +6,4 @@ void saveLogout() async { await preferences.setString('LastUser', ""); await preferences.setString('LastToken', ""); await preferences.setString('LastEmail', ""); - await preferences.setString('username', ""); - await preferences.setString('password', ""); } diff --git a/lib/pages/receipt_page_2.dart b/lib/pages/receipt_page_2.dart index 83f5892..4ef3c00 100644 --- a/lib/pages/receipt_page_2.dart +++ b/lib/pages/receipt_page_2.dart @@ -112,6 +112,7 @@ class ReceiptPage2State extends State { _categories.add("Fetching categories..."); _futureCats.then((value) { _categories = value; + _categories.insert(0, "Uncategorised"); setState(() {}); }); } @@ -406,8 +407,7 @@ class ReceiptPage2State extends State { height: MediaQuery.of(context) .copyWith() .size - .height / - 3, + .height / 3, child: CupertinoPicker( backgroundColor: Colors.white, children: _categories