Skip to content

Commit de9819a

Browse files
Nullsafety fixes / New ParseObject Fetch method
- Fix unpin method - New ParseObject Fetch method - Fix username/emailAddress/password null in currentUser method - Updated dependencies version - Fix ParseLiveListWidget
1 parent b09fb71 commit de9819a

File tree

7 files changed

+51
-32
lines changed

7 files changed

+51
-32
lines changed

packages/dart/lib/src/objects/parse_base.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ abstract class ParseBase {
235235
///
236236
/// Replicates Android SDK pin process and saves object to storage
237237
Future<bool> unpin({String? key}) async {
238-
if (objectId != null) {
238+
if (objectId != null || key != null) {
239239
await ParseCoreData().getStore().remove(key ?? objectId!);
240240
return true;
241241
}
@@ -247,12 +247,12 @@ abstract class ParseBase {
247247
///
248248
/// Replicates Android SDK pin process and saves object to storage
249249
dynamic fromPin(String objectId) async {
250-
final CoreStore coreStore = ParseCoreData().getStore();
251-
final String? itemFromStore = await coreStore.getString(objectId);
250+
final CoreStore coreStore = ParseCoreData().getStore();
251+
final String? itemFromStore = await coreStore.getString(objectId);
252252

253-
if (itemFromStore != null) {
254-
return fromJson(json.decode(itemFromStore));
255-
}
253+
if (itemFromStore != null) {
254+
return fromJson(json.decode(itemFromStore));
255+
}
256256
return null;
257257
}
258258

packages/dart/lib/src/objects/parse_object.dart

+16
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,20 @@ class ParseObject extends ParseBase implements ParseCloneable {
448448
return handleException(e, ParseApiRQ.delete, _debug, parseClassName);
449449
}
450450
}
451+
452+
///Fetches this object with the data from the server. Call this whenever you want the state of the
453+
///object to reflect exactly what is on the server.
454+
Future<ParseObject> fetch() async {
455+
if (objectId == null || objectId!.isEmpty) {
456+
throw 'can not fetch without a objectId';
457+
}
458+
459+
final ParseResponse response = await this.getObject(this.objectId!);
460+
461+
if (response.success && response.results != null) {
462+
return response.results!.first;
463+
} else {
464+
return this;
465+
}
466+
}
451467
}

packages/dart/lib/src/objects/parse_user.dart

+14-10
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
2424
autoSendSessionId: true,
2525
debug: debug,
2626
) {
27-
this.username = username;
28-
this.emailAddress = emailAddress;
29-
this.password = password;
30-
this.sessionToken = sessionToken;
27+
if (username != null) this.username = username;
28+
if (emailAddress != null) this.emailAddress = emailAddress;
29+
if (password != null) this.password = password;
30+
if (sessionToken != null) this.sessionToken = sessionToken;
3131
}
3232

3333
ParseUser.forQuery() : super(keyClassUser);
@@ -51,8 +51,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
5151
set password(String? password) {
5252
if (_password != password) {
5353
_password = password;
54-
if (password != null)
55-
_unsavedChanges[keyVarPassword] = password;
54+
if (password != null) _unsavedChanges[keyVarPassword] = password;
5655
}
5756
}
5857

@@ -111,7 +110,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
111110
///
112111
/// Uses token to get the latest version of the user. Prefer this to [getCurrentUserFromServer]
113112
/// if using custom ParseUser object
114-
Future<ParseResponse?> getUpdatedUser({bool? debug, ParseClient? client}) async {
113+
Future<ParseResponse> getUpdatedUser(
114+
{bool? debug, ParseClient? client}) async {
115115
final bool _debug = isDebugEnabled(objectLevelDebug: debug);
116116
final ParseClient _client = client ??
117117
ParseCoreData().clientCreator(
@@ -120,7 +120,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
120120

121121
// We can't get the current user and session without a sessionId
122122
if ((ParseCoreData().sessionId == null) && (sessionToken == null)) {
123-
return null;
123+
///return null;
124+
throw 'can not get the current user and session without a sessionId';
124125
}
125126

126127
final Map<String, String> headers = <String, String>{};
@@ -192,7 +193,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
192193
options: ParseNetworkOptions(headers: <String, String>{
193194
keyHeaderRevocableSession: '1',
194195
if (installationId != null && !doNotSendInstallationID)
195-
keyHeaderInstallationId: installationId,
196+
keyHeaderInstallationId: installationId,
196197
}),
197198
data: body);
198199

@@ -274,7 +275,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
274275
/// Set [doNotSendInstallationID] to 'true' in order to prevent the SDK from sending the installationID to the Server.
275276
/// This option is especially useful if you are running you application on web and you don't have permission to add 'X-Parse-Installation-Id' as an allowed header on your parse-server.
276277
static Future<ParseResponse> loginWith(String provider, Object authData,
277-
{bool doNotSendInstallationID = false, String? username, String? password, String? email}) async {
278+
{bool doNotSendInstallationID = false,
279+
String? username,
280+
String? password,
281+
String? email}) async {
278282
final ParseUser user = ParseUser.createUser(username, password, email);
279283
final ParseResponse response = await user._loginWith(provider, authData,
280284
doNotSendInstallationID: doNotSendInstallationID);

packages/dart/pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ environment:
99
dependencies:
1010

1111
# Networking
12-
dio: ^4.0.0-prev3
12+
dio: ^4.0.0
1313
http: ^0.13.1
1414
web_socket_channel: ^2.0.0
1515

@@ -19,12 +19,12 @@ dependencies:
1919
xxtea: ^2.1.0
2020

2121
# Utils
22-
uuid: ^3.0.2
22+
uuid: ^3.0.3
2323
meta: ^1.3.0
2424
path: ^1.8.0
2525
mime_type: ^1.0.0
2626

2727
dev_dependencies:
2828
# Testing
29-
mockito: ^5.0.2
29+
mockito: ^5.0.3
3030
test: ^1.16.8

packages/flutter/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,9 @@ class OAuthLogin {
744744
GoogleSignInAccount account = await _googleSignIn.signIn();
745745
GoogleSignInAuthentication authentication = await account.authentication;
746746
await ParseUser.loginWith(
747-
'google',
748-
google(_googleSignIn.currentUser.id,
749-
authentication.accessToken,
750-
authentication.idToken));
747+
'google',
748+
google(authentication.accessToken!, _googleSignIn.currentUser!.id,
749+
authentication.idToken!));
751750
}
752751
}
753752
```

packages/flutter/lib/src/utils/parse_live_list.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ParseLiveListWidget<T extends sdk.ParseObject> extends StatefulWidget {
5050
@override
5151
_ParseLiveListWidgetState<T> createState() => _ParseLiveListWidgetState<T>(
5252
query: query,
53-
removedItemBuilder: removedItemBuilder!,
53+
removedItemBuilder: removedItemBuilder,
5454
listenOnAllSubItems: listenOnAllSubItems,
5555
listeningIncludes: listeningIncludes,
5656
lazyLoading: lazyLoading,
@@ -145,7 +145,7 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
145145
sdk.ParseLiveList<T>? _liveList;
146146
final GlobalKey<AnimatedListState> _animatedListKey =
147147
GlobalKey<AnimatedListState>();
148-
final ChildBuilder<T> removedItemBuilder;
148+
final ChildBuilder<T>? removedItemBuilder;
149149
bool noData = true;
150150

151151
@override
@@ -226,7 +226,7 @@ class ParseLiveListElementWidget<T extends sdk.ParseObject>
226226
}
227227
}
228228

229-
class _ParseLiveListElementWidgetState<T extends sdk.ParseObject >
229+
class _ParseLiveListElementWidgetState<T extends sdk.ParseObject>
230230
extends State<ParseLiveListElementWidget<T>>
231231
with SingleTickerProviderStateMixin {
232232
_ParseLiveListElementWidgetState(sdk.DataGetter<T>? loadedDataGetter,

packages/flutter/pubspec.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ dependencies:
1111
sdk: flutter
1212

1313
parse_server_sdk:
14-
# path: ../dart
15-
git:
16-
url: git://github.com/parse-community/Parse-SDK-Flutter.git
17-
ref: nullsafety
18-
path: packages/dart
14+
path: ../dart
15+
# git:
16+
# url: git://github.com/parse-community/Parse-SDK-Flutter.git
17+
# ref: nullsafety
18+
# path: packages/dart
1919

2020
# Networking
21-
dio: ^4.0.0-prev3
21+
dio: ^4.0.0
2222
connectivity: ^3.0.3 # only used in the flutter part
2323

2424
#Database

0 commit comments

Comments
 (0)