logout works properly
This commit is contained in:
parent
204cd74544
commit
96fdc01eea
4 changed files with 13 additions and 24 deletions
|
@ -1,13 +1,13 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:local_spend/common/functions/get_token.dart';
|
import 'package:local_spend/common/functions/get_token.dart';
|
||||||
import 'package:local_spend/common/functions/save_logout.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 {
|
Future<bool> requestLogoutAPI() async {
|
||||||
|
saveLogout();
|
||||||
|
|
||||||
final url = "https://dev.localspend.co.uk/api/logout";
|
final url = "https://dev.localspend.co.uk/api/logout";
|
||||||
|
|
||||||
var token;
|
var token;
|
||||||
|
@ -20,20 +20,10 @@ Future<LoginModel> requestLogoutAPI(BuildContext context) async {
|
||||||
"Token": token,
|
"Token": token,
|
||||||
};
|
};
|
||||||
|
|
||||||
final response = await http.post(
|
await http.post(
|
||||||
url,
|
url,
|
||||||
body: json.encode(body),
|
body: json.encode(body),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
return true;
|
||||||
// debugPrint("Logout successful: " + response.body);
|
|
||||||
|
|
||||||
saveLogout();
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
// debugPrint("Logout unsuccessful: " + response.body);
|
|
||||||
|
|
||||||
saveLogout();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:local_spend/common/apifunctions/request_logout_api.dart';
|
import 'package:local_spend/common/apifunctions/request_logout_api.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:local_spend/common/functions/save_logout.dart';
|
||||||
|
|
||||||
void logout(context) {
|
void logout(context) {
|
||||||
requestLogoutAPI(context);
|
_clearLoginDetails().then((_) {
|
||||||
Navigator.of(context).pushReplacementNamed('/LoginPage');
|
requestLogoutAPI();
|
||||||
_clearLoginDetails();
|
Navigator.of(context).pushReplacementNamed('/LoginPage');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _clearLoginDetails() async {
|
Future<void> _clearLoginDetails() async {
|
||||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
await preferences.setString('username', "");
|
await preferences.setString('username', "");
|
||||||
await preferences.setString('password', "");
|
await preferences.setString('password', "");
|
||||||
print("details cleared");
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,4 @@ void saveLogout() async {
|
||||||
await preferences.setString('LastUser', "");
|
await preferences.setString('LastUser', "");
|
||||||
await preferences.setString('LastToken', "");
|
await preferences.setString('LastToken', "");
|
||||||
await preferences.setString('LastEmail', "");
|
await preferences.setString('LastEmail', "");
|
||||||
await preferences.setString('username', "");
|
|
||||||
await preferences.setString('password', "");
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,7 @@ class ReceiptPage2State extends State<ReceiptPage2> {
|
||||||
_categories.add("Fetching categories...");
|
_categories.add("Fetching categories...");
|
||||||
_futureCats.then((value) {
|
_futureCats.then((value) {
|
||||||
_categories = value;
|
_categories = value;
|
||||||
|
_categories.insert(0, "Uncategorised");
|
||||||
setState(() {});
|
setState(() {});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -406,8 +407,7 @@ class ReceiptPage2State extends State<ReceiptPage2> {
|
||||||
height: MediaQuery.of(context)
|
height: MediaQuery.of(context)
|
||||||
.copyWith()
|
.copyWith()
|
||||||
.size
|
.size
|
||||||
.height /
|
.height / 3,
|
||||||
3,
|
|
||||||
child: CupertinoPicker(
|
child: CupertinoPicker(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
children: _categories
|
children: _categories
|
||||||
|
|
Reference in a new issue