Skip to content

Commit 9df13e1

Browse files
committed
Version 1.0.6 - Log out function corrected/unpin issue corrected
1 parent 9a7d7aa commit 9df13e1

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

example/lib/main.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,11 @@ class _MyAppState extends State<MyApp> {
143143

144144
response = await user.login();
145145
if (response.success) user = response.result;
146-
user = null;
147146

147+
user = null;
148148
// Best practice for starting the app. This will check for a valid user
149149
user = await ParseUser.currentUser();
150-
user.logout();
151-
150+
await user.logout();
152151
user = await ParseUser.currentUser();
153152

154153
response = await user.getCurrentUserFromServer();

lib/src/data/parse_core_data.dart

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ part of flutter_parse_sdk;
33
/// Singleton class that defines all user keys and data
44
class ParseCoreData {
55
static ParseCoreData _instance;
6+
67
static ParseCoreData get instance => _instance;
78

89
/// Creates an instance of Parse Server
910
///
1011
/// This class should not be user unless switching servers during the app,
1112
/// which is odd. Should only be user by Parse.init
12-
static void init(appId, serverUrl, {debug, appName, liveQueryUrl, masterKey, sessionId}){
13-
_instance = ParseCoreData._init(appId, serverUrl);
14-
15-
if (debug != null) _instance.debug = debug;
16-
if (appName != null) _instance.appName = appName;
17-
if (liveQueryUrl != null) _instance.liveQueryURL = liveQueryUrl;
18-
if (masterKey != null) _instance.masterKey = masterKey;
19-
if (sessionId != null) _instance.sessionId = sessionId;
13+
static void init(appId, serverUrl,
14+
{debug, appName, liveQueryUrl, masterKey, sessionId}) {
15+
_instance = ParseCoreData._init(appId, serverUrl);
16+
17+
if (debug != null) _instance.debug = debug;
18+
if (appName != null) _instance.appName = appName;
19+
if (liveQueryUrl != null) _instance.liveQueryURL = liveQueryUrl;
20+
if (masterKey != null) _instance.masterKey = masterKey;
21+
if (sessionId != null) _instance.sessionId = sessionId;
2022
}
2123

2224
String appName;
@@ -28,8 +30,7 @@ class ParseCoreData {
2830
bool debug;
2931
SharedPreferences storage;
3032

31-
ParseCoreData._init(
32-
this.applicationId,
33+
ParseCoreData._init(this.applicationId,
3334
this.serverUrl);
3435

3536
factory ParseCoreData() => _instance;
@@ -38,15 +39,17 @@ class ParseCoreData {
3839
///
3940
/// This is generated when a users logs in, or calls currentUser to update
4041
/// their keys
41-
void setSessionId(String sessionId){
42+
void setSessionId(String sessionId) {
4243
this.sessionId = sessionId;
4344
}
4445

4546
void initStorage() async {
4647
storage = await SharedPreferences.getInstance();
4748
}
4849

49-
SharedPreferences getStore() => storage;
50+
Future<SharedPreferences> getStore() async {
51+
return storage != null ? storage : await SharedPreferences.getInstance();
52+
}
5053

5154
@override
5255
String toString() => "$applicationId $masterKey";

lib/src/objects/parse_base.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ abstract class ParseBase {
9292

9393
/// Saves in storage
9494
@protected
95-
void saveInStorage(String key) async =>
96-
await ParseCoreData().getStore().setString(key, toString());
95+
void saveInStorage(String key) async {
96+
await ParseCoreData().getStore()
97+
..setString(key, toString());
98+
}
9799

98100
/// Sets type [T] from objectData
99101
///
@@ -132,11 +134,9 @@ abstract class ParseBase {
132134
/// Replicates Android SDK pin process and saves object to storage
133135
Future<bool> pin() async {
134136
if (objectId != null) {
137+
await unpin();
135138
var objectToSave = json.encode(toJson());
136-
ParseCoreData().getStore().remove(objectId);
137-
await ParseCoreData()
138-
.getStore()
139-
.setString(objectId, objectToSave);
139+
await ParseCoreData().getStore()..setString(objectId, objectToSave);
140140
return true;
141141
} else {
142142
return false;
@@ -148,8 +148,7 @@ abstract class ParseBase {
148148
/// Replicates Android SDK pin process and saves object to storage
149149
Future<bool> unpin() async {
150150
if (objectId != null) {
151-
await ParseCoreData().getStore().setString(objectId, "");
152-
await ParseCoreData().getStore().remove(objectId);
151+
await SharedPreferences.getInstance()..remove(objectId);
153152
return true;
154153
}
155154

@@ -159,9 +158,9 @@ abstract class ParseBase {
159158
/// Saves item to simple key pair value storage
160159
///
161160
/// Replicates Android SDK pin process and saves object to storage
162-
fromPin(String objectId) {
161+
fromPin(String objectId) async {
163162
if (objectId != null) {
164-
var itemFromStore = ParseCoreData().getStore().getString(objectId);
163+
var itemFromStore = (await ParseCoreData().getStore()).getString(objectId);
165164

166165
if (itemFromStore != null) {
167166
var map = json.decode(itemFromStore);

lib/src/objects/parse_user.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
239239
}
240240
}
241241

242-
static ParseUser _getUserFromLocalStore() {
243-
var userJson = ParseCoreData().getStore().getString(keyParseStoreUser);
242+
static Future<ParseUser> _getUserFromLocalStore() async {
243+
var userJson = (await ParseCoreData().getStore()).getString(keyParseStoreUser);
244244

245245
if (userJson != null) {
246246
var userMap = JsonDecoder().convert(userJson);

0 commit comments

Comments
 (0)