Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #15

Merged
merged 5 commits into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/lib/diet_plan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DietPlan extends ParseObject {
static const String STATUS = 'Status';

@override
dynamic fromJson(Map<String, dynamic> objectData) {
dynamic fromJson(Map objectData) {
this.name = objectData[NAME];
this.description = objectData[DESCRIPTION];
this.protein = objectData[PROTEIN];
Expand Down
96 changes: 49 additions & 47 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_plugin_example/application_constants.dart';
import 'package:flutter_plugin_example/diet_plan.dart';
import 'package:parse_server_sdk/objects/parse_object.dart';
import 'package:parse_server_sdk/network/parse_query.dart';
import 'package:parse_server_sdk/objects/parse_response.dart';
import 'package:parse_server_sdk/objects/parse_object.dart';
import 'package:parse_server_sdk/objects/parse_user.dart';
import 'package:parse_server_sdk/parse.dart';

Expand All @@ -17,7 +14,6 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {

@override
void initState() {
super.initState();
Expand All @@ -35,84 +31,90 @@ class _MyAppState extends State<MyApp> {
body: new Center(
child: new Text('Running Parse init'),
),
floatingActionButton: new FloatingActionButton(onPressed: runTestQueries),
floatingActionButton:
new FloatingActionButton(onPressed: runTestQueries),
),
);
}

initParse() async {
// Initialize parse
Parse().initialize(
ApplicationConstants.PARSE_APPLICATION_ID,
Parse().initialize(ApplicationConstants.PARSE_APPLICATION_ID,
ApplicationConstants.PARSE_SERVER_URL,
masterKey: ApplicationConstants.PARSE_MASTER_KEY,
appName: ApplicationConstants.APP_NAME,
debug: true
);
debug: true);
}

runTestQueries(){
getAllItems();
getAllItemsByName();
getSingleItem();
runTestQueries() {
//getAllItems();
//getAllItemsByName();
//getSingleItem();
query();
initUser();
//initUser();
}

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

if (apiResponse.success){
if (apiResponse.success) {
for (var testObject in apiResponse.result) {
print(ApplicationConstants.APP_NAME + ": " + testObject.toString());
}
}
}

void getAllItems() async {
var dietPlans = await DietPlan().getAll();

if (dietPlans.success) {
for (var plan in dietPlans.result) {
print(ApplicationConstants.APP_NAME + ": " + (plan as DietPlan).name);
}
} else {
print(ApplicationConstants.APP_NAME + ": " + dietPlans.exception.message);
var response = await DietPlan().getAll();

if (response.success) {
for (var plan in response.result) {
print(ApplicationConstants.APP_NAME + ": " + (plan as DietPlan).name);
}
} else {
print(ApplicationConstants.APP_NAME + ": " + response.exception.message);
}
}

void getSingleItem() async {
var dietPlan = await DietPlan().get('R5EonpUDWy');
var response = await DietPlan().get('R5EonpUDWy');

if (dietPlan.success) {
print(ApplicationConstants.APP_NAME + ": " + (dietPlan.result as DietPlan).toString());
if (response.success) {
print(ApplicationConstants.APP_NAME +
": " +
(response.result as DietPlan).toString());
} else {
print(ApplicationConstants.APP_NAME + ": " + dietPlan.exception.message);
print(ApplicationConstants.APP_NAME + ": " + response.exception.message);
}
}

void query() {
void query() async {
// Query for an object by name
QueryBuilder()
..object = DietPlan()
..field = DietPlan.NAME
..equals = ['Paleo']
..query().then((response) {
if (response.success) {
print(ApplicationConstants.APP_NAME +
": " +
((response.result as List<dynamic>).first as DietPlan)
.toString());
} else {
print(ApplicationConstants.APP_NAME +
": " +
response.exception.message);
}
});
var queryBuilder = QueryBuilder<DietPlan>(DietPlan())
..startsWith(DietPlan.NAME, "Keto")
..greaterThan(DietPlan.FAT, 64)
..lessThan(DietPlan.FAT, 66)
..equals(DietPlan.CARBS, 5);

var response = await queryBuilder.query();

if (response.success) {
print(ApplicationConstants.APP_NAME + ": " + ((response.result as List<dynamic>).first as DietPlan).toString());
} else {
print(ApplicationConstants.APP_NAME + ": " + response.exception.message);
}
}

initUser() async {
ParseUser().create("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com");
ParseUser().signUp();
ParseUser()
.create("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com");
var user = await ParseUser().signUp();
user = await ParseUser().login();
user = await ParseUser().currentUser(fromServer: true);
user = await ParseUser().requestPasswordReset();
user = await ParseUser().verificationEmailRequest();
user = await ParseUser().all();
user = await ParseUser().save();
user = await ParseUser().destroy();
}
}
19 changes: 7 additions & 12 deletions lib/data/parse_data_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ class ParseDataServer {
static ParseDataServer get instance => _instance;

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

if (debug != null) _instance..debug = debug;
if (appName != null) _instance..appName = appName;
if (liveQueryUrl != null) _instance..liveQueryURL = liveQueryUrl;
if (masterKey != null) _instance..masterKey = masterKey;
if (sessionId != null) _instance..sessionId = sessionId;
if (debug != null) _instance.debug = debug;
if (appName != null) _instance.appName = appName;
if (liveQueryUrl != null) _instance.liveQueryURL = liveQueryUrl;
if (masterKey != null) _instance.masterKey = masterKey;
if (sessionId != null) _instance.sessionId = sessionId;
}

String appName;
Expand All @@ -22,12 +22,7 @@ class ParseDataServer {

ParseDataServer._init(
this.applicationId,
this.serverUrl,
{this.debug: false,
this.appName: "ParseApplication",
this.liveQueryURL,
this.masterKey,
this.sessionId});
this.serverUrl);

factory ParseDataServer() => _instance;

Expand Down
20 changes: 14 additions & 6 deletions lib/data/parse_data_user.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:parse_server_sdk/base/parse_constants.dart';
import 'package:parse_server_sdk/objects/parse_base.dart';
import 'package:parse_server_sdk/utils/parse_utils_date.dart';

class User extends ParseBase {
static User _instance;
Expand All @@ -17,13 +19,19 @@ class User extends ParseBase {

factory User() => _instance;

fromJson(Map<String, dynamic> objectData) {
setObjectData(objectData);
fromJson(Map objectData) {
if (getObjectData() == null) setObjectData(objectData);
getObjectData().addAll(objectData);
if (getObjectData().containsKey(ParseConstants.OBJECT_ID)) objectId = getValue(ParseConstants.OBJECT_ID).toString();
if (getObjectData().containsKey(ParseConstants.CREATED_AT)) createdAt = convertStringToDateTime(getValue(ParseConstants.CREATED_AT).toString());
if (getObjectData().containsKey(ParseConstants.UPDATED_AT)) updatedAt = convertStringToDateTime(getValue(ParseConstants.UPDATED_AT).toString());
if (getObjectData().containsKey(ACL)) acl = getValue(ACL).toString();
if (getObjectData().containsKey(USERNAME)) username = getValue(USERNAME).toString();
if (getObjectData().containsKey(PASSWORD)) password = getValue(PASSWORD).toString();
if (getObjectData().containsKey(EMAIL)) emailAddress = getValue(EMAIL).toString();

if (updatedAt == null) updatedAt = createdAt;

acl = getObjectData()[ACL];
username = getObjectData()[USERNAME];
password = getObjectData()[PASSWORD];
emailAddress = getObjectData()[EMAIL];
return this;
}

Expand Down
Loading