Skip to content

Commit 2006ff6

Browse files
authored
Merge pull request #15 from phillwiggins/develop
Develop
2 parents e3ef68c + 508f102 commit 2006ff6

File tree

11 files changed

+353
-236
lines changed

11 files changed

+353
-236
lines changed

example/lib/diet_plan.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DietPlan extends ParseObject {
2121
static const String STATUS = 'Status';
2222

2323
@override
24-
dynamic fromJson(Map<String, dynamic> objectData) {
24+
dynamic fromJson(Map objectData) {
2525
this.name = objectData[NAME];
2626
this.description = objectData[DESCRIPTION];
2727
this.protein = objectData[PROTEIN];

example/lib/main.dart

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import 'dart:async';
2-
31
import 'package:flutter/material.dart';
42
import 'package:flutter_plugin_example/application_constants.dart';
53
import 'package:flutter_plugin_example/diet_plan.dart';
6-
import 'package:parse_server_sdk/objects/parse_object.dart';
74
import 'package:parse_server_sdk/network/parse_query.dart';
8-
import 'package:parse_server_sdk/objects/parse_response.dart';
5+
import 'package:parse_server_sdk/objects/parse_object.dart';
96
import 'package:parse_server_sdk/objects/parse_user.dart';
107
import 'package:parse_server_sdk/parse.dart';
118

@@ -17,7 +14,6 @@ class MyApp extends StatefulWidget {
1714
}
1815

1916
class _MyAppState extends State<MyApp> {
20-
2117
@override
2218
void initState() {
2319
super.initState();
@@ -35,84 +31,90 @@ class _MyAppState extends State<MyApp> {
3531
body: new Center(
3632
child: new Text('Running Parse init'),
3733
),
38-
floatingActionButton: new FloatingActionButton(onPressed: runTestQueries),
34+
floatingActionButton:
35+
new FloatingActionButton(onPressed: runTestQueries),
3936
),
4037
);
4138
}
4239

4340
initParse() async {
4441
// Initialize parse
45-
Parse().initialize(
46-
ApplicationConstants.PARSE_APPLICATION_ID,
42+
Parse().initialize(ApplicationConstants.PARSE_APPLICATION_ID,
4743
ApplicationConstants.PARSE_SERVER_URL,
4844
masterKey: ApplicationConstants.PARSE_MASTER_KEY,
4945
appName: ApplicationConstants.APP_NAME,
50-
debug: true
51-
);
46+
debug: true);
5247
}
5348

54-
runTestQueries(){
55-
getAllItems();
56-
getAllItemsByName();
57-
getSingleItem();
49+
runTestQueries() {
50+
//getAllItems();
51+
//getAllItemsByName();
52+
//getSingleItem();
5853
query();
59-
initUser();
54+
//initUser();
6055
}
6156

6257
void getAllItemsByName() async {
6358
var apiResponse = await ParseObject('ParseTableName').getAll();
6459

65-
if (apiResponse.success){
60+
if (apiResponse.success) {
6661
for (var testObject in apiResponse.result) {
6762
print(ApplicationConstants.APP_NAME + ": " + testObject.toString());
6863
}
6964
}
7065
}
7166

7267
void getAllItems() async {
73-
var dietPlans = await DietPlan().getAll();
74-
75-
if (dietPlans.success) {
76-
for (var plan in dietPlans.result) {
77-
print(ApplicationConstants.APP_NAME + ": " + (plan as DietPlan).name);
78-
}
79-
} else {
80-
print(ApplicationConstants.APP_NAME + ": " + dietPlans.exception.message);
68+
var response = await DietPlan().getAll();
69+
70+
if (response.success) {
71+
for (var plan in response.result) {
72+
print(ApplicationConstants.APP_NAME + ": " + (plan as DietPlan).name);
8173
}
74+
} else {
75+
print(ApplicationConstants.APP_NAME + ": " + response.exception.message);
76+
}
8277
}
8378

8479
void getSingleItem() async {
85-
var dietPlan = await DietPlan().get('R5EonpUDWy');
80+
var response = await DietPlan().get('R5EonpUDWy');
8681

87-
if (dietPlan.success) {
88-
print(ApplicationConstants.APP_NAME + ": " + (dietPlan.result as DietPlan).toString());
82+
if (response.success) {
83+
print(ApplicationConstants.APP_NAME +
84+
": " +
85+
(response.result as DietPlan).toString());
8986
} else {
90-
print(ApplicationConstants.APP_NAME + ": " + dietPlan.exception.message);
87+
print(ApplicationConstants.APP_NAME + ": " + response.exception.message);
9188
}
9289
}
9390

94-
void query() {
91+
void query() async {
9592
// Query for an object by name
96-
QueryBuilder()
97-
..object = DietPlan()
98-
..field = DietPlan.NAME
99-
..equals = ['Paleo']
100-
..query().then((response) {
101-
if (response.success) {
102-
print(ApplicationConstants.APP_NAME +
103-
": " +
104-
((response.result as List<dynamic>).first as DietPlan)
105-
.toString());
106-
} else {
107-
print(ApplicationConstants.APP_NAME +
108-
": " +
109-
response.exception.message);
110-
}
111-
});
93+
var queryBuilder = QueryBuilder<DietPlan>(DietPlan())
94+
..startsWith(DietPlan.NAME, "Keto")
95+
..greaterThan(DietPlan.FAT, 64)
96+
..lessThan(DietPlan.FAT, 66)
97+
..equals(DietPlan.CARBS, 5);
98+
99+
var response = await queryBuilder.query();
100+
101+
if (response.success) {
102+
print(ApplicationConstants.APP_NAME + ": " + ((response.result as List<dynamic>).first as DietPlan).toString());
103+
} else {
104+
print(ApplicationConstants.APP_NAME + ": " + response.exception.message);
105+
}
112106
}
113107

114108
initUser() async {
115-
ParseUser().create("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com");
116-
ParseUser().signUp();
109+
ParseUser()
110+
.create("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com");
111+
var user = await ParseUser().signUp();
112+
user = await ParseUser().login();
113+
user = await ParseUser().currentUser(fromServer: true);
114+
user = await ParseUser().requestPasswordReset();
115+
user = await ParseUser().verificationEmailRequest();
116+
user = await ParseUser().all();
117+
user = await ParseUser().save();
118+
user = await ParseUser().destroy();
117119
}
118120
}

lib/data/parse_data_server.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ class ParseDataServer {
33
static ParseDataServer get instance => _instance;
44

55
static void init(appId, serverUrl, {debug, appName, liveQueryUrl, masterKey, sessionId}){
6-
_instance ??= ParseDataServer._init(appId, serverUrl);
6+
_instance = ParseDataServer._init(appId, serverUrl);
77

8-
if (debug != null) _instance..debug = debug;
9-
if (appName != null) _instance..appName = appName;
10-
if (liveQueryUrl != null) _instance..liveQueryURL = liveQueryUrl;
11-
if (masterKey != null) _instance..masterKey = masterKey;
12-
if (sessionId != null) _instance..sessionId = sessionId;
8+
if (debug != null) _instance.debug = debug;
9+
if (appName != null) _instance.appName = appName;
10+
if (liveQueryUrl != null) _instance.liveQueryURL = liveQueryUrl;
11+
if (masterKey != null) _instance.masterKey = masterKey;
12+
if (sessionId != null) _instance.sessionId = sessionId;
1313
}
1414

1515
String appName;
@@ -22,12 +22,7 @@ class ParseDataServer {
2222

2323
ParseDataServer._init(
2424
this.applicationId,
25-
this.serverUrl,
26-
{this.debug: false,
27-
this.appName: "ParseApplication",
28-
this.liveQueryURL,
29-
this.masterKey,
30-
this.sessionId});
25+
this.serverUrl);
3126

3227
factory ParseDataServer() => _instance;
3328

lib/data/parse_data_user.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import 'package:parse_server_sdk/base/parse_constants.dart';
12
import 'package:parse_server_sdk/objects/parse_base.dart';
3+
import 'package:parse_server_sdk/utils/parse_utils_date.dart';
24

35
class User extends ParseBase {
46
static User _instance;
@@ -17,13 +19,19 @@ class User extends ParseBase {
1719

1820
factory User() => _instance;
1921

20-
fromJson(Map<String, dynamic> objectData) {
21-
setObjectData(objectData);
22+
fromJson(Map objectData) {
23+
if (getObjectData() == null) setObjectData(objectData);
24+
getObjectData().addAll(objectData);
25+
if (getObjectData().containsKey(ParseConstants.OBJECT_ID)) objectId = getValue(ParseConstants.OBJECT_ID).toString();
26+
if (getObjectData().containsKey(ParseConstants.CREATED_AT)) createdAt = convertStringToDateTime(getValue(ParseConstants.CREATED_AT).toString());
27+
if (getObjectData().containsKey(ParseConstants.UPDATED_AT)) updatedAt = convertStringToDateTime(getValue(ParseConstants.UPDATED_AT).toString());
28+
if (getObjectData().containsKey(ACL)) acl = getValue(ACL).toString();
29+
if (getObjectData().containsKey(USERNAME)) username = getValue(USERNAME).toString();
30+
if (getObjectData().containsKey(PASSWORD)) password = getValue(PASSWORD).toString();
31+
if (getObjectData().containsKey(EMAIL)) emailAddress = getValue(EMAIL).toString();
32+
33+
if (updatedAt == null) updatedAt = createdAt;
2234

23-
acl = getObjectData()[ACL];
24-
username = getObjectData()[USERNAME];
25-
password = getObjectData()[PASSWORD];
26-
emailAddress = getObjectData()[EMAIL];
2735
return this;
2836
}
2937

0 commit comments

Comments
 (0)