Skip to content

Commit 9e3997f

Browse files
Merge pull request #645 from RodrigoSMarques/nullsafety
New method for ParseQuery / Bugfix ParseQuery methods / Bugfix ParseRelation.getQuery
2 parents a25d4a9 + 8432589 commit 9e3997f

File tree

12 files changed

+80
-38
lines changed

12 files changed

+80
-38
lines changed

packages/dart/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 3.1.0
2+
Bug fixes
3+
General improvements
4+
Updated dependencies
5+
6+
## 3.0.0
7+
Stable null safety release.
8+
19
## 2.1.0
210
Option para uses ParseHTTPClient (default) or ParseDioClient (slow on Flutter Web).
311
**BREAKING CHANGE** if use progress callback at the file upload in version 2.0.1
@@ -6,6 +14,7 @@ Changed to the method POST on Login
614
Bug fixes
715
General improvements
816
Updated dependencies
17+
918
## 2.0.1
1019
Fixed network exceptions. [#482](https://github.com/parse-community/Parse-SDK-Flutter/pull/482)
1120

packages/dart/README.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@ This is a Dart package that allows communication with a Parse Server, (https://p
1717
This is a work in progress and we are consistently updating it. Please let us know if you think anything needs changing/adding, and more than ever, please do join in on this project. (Even if it is just to improve our documentation)
1818

1919
## Getting Started
20-
To install, either add to your pubspec.yaml
21-
```yml
22-
dependencies:
23-
parse_server_sdk: ^2.1.0
24-
```
25-
or clone this repository and add to your project. As this is an early development with multiple contributors, it is probably best to download/clone and keep updating as an when a new feature is added.
2620

21+
To install, either add [dependency in your pubspec.yaml file](https://pub.dev/packages/parse_server_sdk/install).
2722

2823
Once you have the library added to your project, upon first call to your app (Similar to what your application class would be) add the following...
2924

@@ -66,7 +61,6 @@ When running via express, set [ParseServerOptions](https://parseplatform.org/par
6661

6762
Be aware that for web ParseInstallation does include app name, version or package identifier.
6863

69-
7064
## Objects
7165
You can create custom objects by calling:
7266
```dart
@@ -312,6 +306,7 @@ The features available are:-
312306
* WithinKilometers
313307
* WithinRadians
314308
* WithinGeoBox
309+
* WithinPolygon
315310
* MatchesQuery
316311
* DoesNotMatchQuery
317312
* MatchesKeyInQuery

packages/dart/lib/src/network/parse_query.dart

+25-9
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ class QueryBuilder<T extends ParseObject> {
115115
{bool caseSensitive = false}) {
116116
if (caseSensitive) {
117117
queries.add(MapEntry<String, dynamic>(
118-
_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$query^\"}'));
118+
_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$query\$\"}'));
119119
} else {
120120
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
121-
'\"$column\":{\"\$regex\": \"$query^\", \"\$options\": \"i\"}'));
121+
'\"$column\":{\"\$regex\": \"$query\$\", \"\$options\": \"i\"}'));
122122
}
123123
}
124124

@@ -226,11 +226,14 @@ class QueryBuilder<T extends ParseObject> {
226226
/// Powerful search for containing whole words. This search is much quicker than regex and can search for whole words including wether they are case sensitive or not.
227227
/// This search can also order by the score of the search
228228
void whereContainsWholeWord(String column, String query,
229-
{bool caseSensitive = false, bool orderByScore = true}) {
229+
{bool caseSensitive = false,
230+
bool orderByScore = true,
231+
bool diacriticSensitive = false}) {
230232
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
231-
'\"$column\":{\"\$text\":{\"\$search\":{\"\$term\": \"$query\", \"\$caseSensitive\": $caseSensitive }}}'));
233+
'\"$column\":{\"\$text\":{\"\$search\":{\"\$term\": \"$query\", \"\$caseSensitive\": $caseSensitive , \"\$diacriticSensitive\": $diacriticSensitive }}}'));
232234
if (orderByScore) {
233-
orderByDescending('score');
235+
orderByAscending('\$score');
236+
keysToReturn(['\$score']);
234237
}
235238
}
236239

@@ -285,7 +288,20 @@ class QueryBuilder<T extends ParseObject> {
285288
'\"$column\":{\"\$within\":{\"\$box\": [{\"__type\": \"GeoPoint\",\"latitude\":$latitudeS,\"longitude\":$longitudeS},{\"__type\": \"GeoPoint\",\"latitude\":$latitudeN,\"longitude\":$longitudeN}]}}'));
286289
}
287290

288-
// Add a constraint to the query that requires a particular key's value match another QueryBuilder
291+
/// Return an object with key coordinates be contained within and on the bounds of a given polygon.
292+
/// Supports closed and open (last point is connected to first) paths
293+
/// Polygon must have at least 3 points
294+
void whereWithinPolygon(String column, List<ParseGeoPoint> points) {
295+
if (points.length < 3)
296+
throw ArgumentError('Polygon must have at least 3 points');
297+
Map<String, dynamic> dictionary = <String, dynamic>{};
298+
dictionary['\$polygon'] = points.map((e) => e.toJson()).toList();
299+
300+
queries.add(MapEntry<String, dynamic>(_SINGLE_QUERY,
301+
'\"$column\":{\"\$geoWithin\":${jsonEncode(dictionary)}}'));
302+
}
303+
304+
/// Add a constraint to the query that requires a particular key's value match another QueryBuilder
289305
void whereMatchesQuery<E extends ParseObject>(
290306
String column, QueryBuilder<E> query) {
291307
final String inQuery =
@@ -295,7 +311,7 @@ class QueryBuilder<T extends ParseObject> {
295311
_SINGLE_QUERY, '\"$column\":{\"\$inQuery\":$inQuery}'));
296312
}
297313

298-
//Add a constraint to the query that requires a particular key's value does not match another QueryBuilder
314+
///Add a constraint to the query that requires a particular key's value does not match another QueryBuilder
299315
void whereDoesNotMatchQuery<E extends ParseObject>(
300316
String column, QueryBuilder<E> query) {
301317
final String inQuery =
@@ -305,7 +321,7 @@ class QueryBuilder<T extends ParseObject> {
305321
_SINGLE_QUERY, '\"$column\":{\"\$notInQuery\":$inQuery}'));
306322
}
307323

308-
// Add a constraint to the query that requires a particular key's value matches a value for a key in the results of another ParseQuery.
324+
/// Add a constraint to the query that requires a particular key's value matches a value for a key in the results of another ParseQuery.
309325
void whereMatchesKeyInQuery<E extends ParseObject>(
310326
String column, String keyInQuery, QueryBuilder<E> query) {
311327
if (query.queries.isEmpty) {
@@ -325,7 +341,7 @@ class QueryBuilder<T extends ParseObject> {
325341
_SINGLE_QUERY, '\"$column\":{\"\$select\":$inQuery}'));
326342
}
327343

328-
// Add a constraint to the query that requires a particular key's value does not match any value for a key in the results of another ParseQuery
344+
/// Add a constraint to the query that requires a particular key's value does not match any value for a key in the results of another ParseQuery
329345
void whereDoesNotMatchKeyInQuery<E extends ParseObject>(
330346
String column, String keyInQuery, QueryBuilder<E> query) {
331347
if (query.queries.isEmpty) {

packages/dart/lib/src/objects/parse_geo_point.dart

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ const String keyLongitude = 'longitude';
55

66
class ParseGeoPoint {
77
/// Creates a Parse Object of type GeoPoint
8-
ParseGeoPoint({this.latitude = 0.0, this.longitude = 0.0});
8+
ParseGeoPoint({this.latitude = 0.0, this.longitude = 0.0})
9+
: assert(
10+
latitude < 90, 'Latitude must be within the range (-90.0, 90.0).'),
11+
assert(
12+
latitude > -90, 'Latitude must be within the range (-90.0, 90.0).'),
13+
assert(latitude < 180,
14+
'Longitude must be within the range (-180.0, 180.0).'),
15+
assert(latitude > -180,
16+
'Longitude must be within the range (-180.0, 180.0).');
917

1018
double latitude, longitude;
1119

@@ -15,4 +23,9 @@ class ParseGeoPoint {
1523
'latitude': latitude,
1624
'longitude': longitude
1725
};
26+
27+
@override
28+
String toString() {
29+
return 'latitude: $latitude, longitude: $longitude';
30+
}
1831
}

packages/dart/lib/src/objects/parse_relation.dart

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ part of flutter_parse_sdk;
33
// ignore_for_file: always_specify_types
44
class ParseRelation<T extends ParseObject> {
55
ParseRelation({required ParseObject parent, required String key}) {
6+
if (!parent.containsKey(key)) {
7+
throw 'Invalid Relation key name';
8+
}
9+
_targetClass = parent.get<ParseRelation>(key)!.getTargetClass;
610
_parent = parent;
711
_key = key;
812
_parentObjectId = parent.objectId!;
@@ -41,6 +45,8 @@ class ParseRelation<T extends ParseObject> {
4145
_parent!.removeRelation(_key, _knownObjects!.toList());
4246
}
4347

48+
String get getTargetClass => _targetClass ?? '';
49+
4450
Map<String, dynamic> toJson() => <String, dynamic>{
4551
'__type': keyRelation,
4652
'className': _targetClass,

packages/dart/pubspec.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ environment:
99
dependencies:
1010
# Networking
1111
dio: ^4.0.0
12-
http: ^0.13.1
13-
web_socket_channel: ^2.0.0
12+
http: ^0.13.3
13+
web_socket_channel: ^2.1.0
1414

1515
#Database
16-
sembast: ^3.0.1
16+
sembast: ^3.1.0+2
1717
sembast_web: ^2.0.0+2
1818
xxtea: ^2.1.0
1919

@@ -25,6 +25,6 @@ dependencies:
2525

2626
dev_dependencies:
2727
# Testing
28-
build_runner: ^2.0.1
29-
mockito: ^5.0.4
30-
test: ^1.16.8
28+
build_runner: ^2.0.4
29+
mockito: ^5.0.10
30+
test: ^1.17.7

packages/flutter/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 3.1.0
2+
Bug fixes
3+
General improvements
4+
Updated dependencies
5+
6+
## 3.0.0
7+
Stable null safety release.
8+
19
## 2.1.0
210
Option para uses ParseHTTPClient (default) or ParseDioClient (slow on Flutter Web).
311
**BREAKING CHANGE** if use progress callback at the file upload in version 2.0.1

packages/flutter/README.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ Hi, this is a Flutter plugin that allows communication with a Parse Server, (htt
1111
This is a work in progress and we are consistently updating it. Please let us know if you think anything needs changing/adding, and more than ever, please do join in on this project. (Even if it is just to improve our documentation)
1212

1313
## Getting Started
14-
To install, either add to your pubspec.yaml
15-
```yml
16-
dependencies:
17-
parse_server_sdk_flutter: ^3.1.0
18-
```
19-
or clone this repository and add to your project. As this is an early development with multiple contributors, it is probably best to download/clone and keep updating as an when a new feature is added.
20-
14+
To install, either add [dependency in your pubspec.yaml file](https://pub.dev/packages/parse_server_sdk_flutter/install).
2115

2216
Once you have the library added to your project, upon first call to your app (Similar to what your application class would be) add the following...
2317

@@ -329,6 +323,7 @@ The features available are:-
329323
* WithinKilometers
330324
* WithinRadians
331325
* WithinGeoBox
326+
* WithinPolygon
332327
* MatchesQuery
333328
* DoesNotMatchQuery
334329
* MatchesKeyInQuery
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
C:/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.0.1/
1+
/Users/rodrigo/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.0.2/
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
C:/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.0.0/
1+
/Users/rodrigo/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.0.0/
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
C:/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.0.0/
1+
/Users/rodrigo/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.0.0/

packages/flutter/pubspec.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ dependencies:
1010
flutter:
1111
sdk: flutter
1212

13-
# Uncomment for Release version
14-
parse_server_sdk: ^3.1.0
13+
#Uncomment for Release version
14+
#parse_server_sdk: ^3.1.0
1515

1616
# Uncomment for local testing
17-
#parse_server_sdk:
18-
# path: ../dart
17+
parse_server_sdk:
18+
path: ../dart
1919

2020
# Uncomment for test with Github Branch
2121
#parse_server_sdk:
@@ -41,4 +41,4 @@ dev_dependencies:
4141
# Testing
4242
flutter_test:
4343
sdk: flutter
44-
mockito: ^5.0.2
44+
mockito: ^5.0.10

0 commit comments

Comments
 (0)