Initial framework in place, non-functional POST & env vars atm
This commit is contained in:
parent
3bc940063a
commit
5c718fc14b
29 changed files with 1263 additions and 170 deletions
8
lib/common/functions/get_token.dart
Normal file
8
lib/common/functions/get_token.dart
Normal file
|
@ -0,0 +1,8 @@
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
getToken() async {
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
String getToken = await preferences.getString("LastToken");
|
||||
return getToken;
|
||||
}
|
30
lib/common/functions/save_current_login.dart
Normal file
30
lib/common/functions/save_current_login.dart
Normal file
|
@ -0,0 +1,30 @@
|
|||
import 'package:local_spend/model/json/login_model.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
saveCurrentLogin(Map responseJson) async {
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
var user;
|
||||
if ((responseJson != null && responseJson.isNotEmpty)) {
|
||||
user = LoginModel.fromJson(responseJson).userName;
|
||||
} else {
|
||||
user = "";
|
||||
}
|
||||
var token = (responseJson != null && responseJson.isNotEmpty)
|
||||
? LoginModel.fromJson(responseJson).token
|
||||
: "";
|
||||
var email = (responseJson != null && responseJson.isNotEmpty)
|
||||
? LoginModel.fromJson(responseJson).email
|
||||
: "";
|
||||
var pk = (responseJson != null && responseJson.isNotEmpty)
|
||||
? LoginModel.fromJson(responseJson).userId
|
||||
: 0;
|
||||
|
||||
await preferences.setString(
|
||||
'LastUser', (user != null && user.length > 0) ? user : "");
|
||||
await preferences.setString(
|
||||
'LastToken', (token != null && token.length > 0) ? token : "");
|
||||
await preferences.setString(
|
||||
'LastEmail', (email != null && email.length > 0) ? email : "");
|
||||
await preferences.setInt('LastUserId', (pk != null && pk > 0) ? pk : 0);
|
||||
}
|
10
lib/common/functions/save_logout.dart
Normal file
10
lib/common/functions/save_logout.dart
Normal file
|
@ -0,0 +1,10 @@
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
saveLogout() async {
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
await preferences.setString('LastUser', "");
|
||||
await preferences.setString('LastToken', "");
|
||||
await preferences.setString('LastEmail', "");
|
||||
await preferences.setInt('LastUserId', 0);
|
||||
}
|
25
lib/common/functions/show_dialog_single_button.dart
Normal file
25
lib/common/functions/show_dialog_single_button.dart
Normal file
|
@ -0,0 +1,25 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
void showDialogSingleButton(
|
||||
BuildContext context, String title, String message, String buttonLabel) {
|
||||
// flutter defined function
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
// return object of type Dialog
|
||||
return AlertDialog(
|
||||
title: new Text(title),
|
||||
content: new Text(message),
|
||||
actions: <Widget>[
|
||||
// usually buttons at the bottom of the dialog
|
||||
new FlatButton(
|
||||
child: new Text(buttonLabel),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
Reference in a new issue