@@ -2,8 +2,11 @@ import 'dart:async';
22
33import 'package:flutter/material.dart' ;
44import 'package:flutter_plugin_example/application_constants.dart' ;
5+ import 'package:flutter_plugin_example/diet_plan.dart' ;
6+ import 'package:parse_server_sdk/objects/parse_object.dart' ;
7+ import 'package:parse_server_sdk/network/parse_query.dart' ;
8+ import 'package:parse_server_sdk/objects/parse_user.dart' ;
59import 'package:parse_server_sdk/parse.dart' ;
6- import 'package:parse_server_sdk/parse_user.dart' ;
710
811void main () => runApp (new MyApp ());
912
@@ -17,19 +20,80 @@ class _MyAppState extends State<MyApp> {
1720 void initState () {
1821 super .initState ();
1922 initParse ();
23+ getAllItems ();
24+ getSingleItem ();
25+ query ();
26+ queryByContainedIn ();
2027 initUser ();
2128 }
2229
2330 Future <void > initParse () async {
31+
32+ // Initialize parse
2433 Parse ().initialize (
2534 appId: ApplicationConstants .PARSE_APPLICATION_ID ,
2635 serverUrl: ApplicationConstants .PARSE_SERVER_URL ,
2736 masterKey: ApplicationConstants .PARSE_MASTER_KEY );
2837 }
2938
39+ void getAllItems () {
40+ DietPlan ().getAll ().then ((response) {
41+ if (response.success){
42+
43+ for (var plan in response.result) {
44+ print (ApplicationConstants .APP_NAME + ": " + (plan as DietPlan ).name);
45+ }
46+
47+ } else {
48+ print (ApplicationConstants .APP_NAME + ": " + response.exception.message);
49+ }
50+ });
51+ }
52+
53+ void getSingleItem () {
54+ DietPlan ().get ('R5EonpUDWy' ).then ((response) {
55+ if (response.success){
56+ print (ApplicationConstants .APP_NAME + ": " + (response.result as DietPlan ).toString ());
57+ } else {
58+ print (ApplicationConstants .APP_NAME + ": " + response.exception.message);
59+ }
60+ });
61+ }
62+
63+ void query () {
64+ // Query for an object by name
65+ QueryBuilder ()
66+ ..object = DietPlan ()
67+ ..field = DietPlan .NAME
68+ ..equals = ['Paleo' ]
69+ ..query ().then ((response){
70+
71+ if (response.success){
72+ print (ApplicationConstants .APP_NAME + ": " + ((response.result as List <ParseObject >)[0 ] as DietPlan ).toString ());
73+ } else {
74+ print (ApplicationConstants .APP_NAME + ": " + response.exception.message);
75+ }
76+ });
77+ }
78+
79+ void queryByContainedIn () {
80+ // Query for an object by name
81+ QueryBuilder ()
82+ ..object = DietPlan ()
83+ ..field = DietPlan .NAME
84+ ..contains = ['Diet' ]
85+ ..query ().then ((response){
86+
87+ if (response.success){
88+ print (ApplicationConstants .APP_NAME + ": " + ((response.result as List <ParseObject >)[0 ] as DietPlan ).toString ());
89+ } else {
90+ print (ApplicationConstants .APP_NAME + ": " + response.exception.message);
91+ }
92+ });
93+ }
94+
3095 Future <void > initUser () async {
31- User ()
32- .
createNewUser (
"TestFlutter" ,
"TestPassword123" ,
"[email protected] " );
96+ User ().
createNewUser (
"TestFlutter" ,
"TestPassword123" ,
"[email protected] " );
3397
3498 User ().login ().then ((val) {
3599 print (val);
@@ -49,4 +113,4 @@ class _MyAppState extends State<MyApp> {
49113 ),
50114 );
51115 }
52- }
116+ }
0 commit comments