Skip to content

Release/1.0.22 #193

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

Merged
merged 14 commits into from
Jun 11, 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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ build/
.idea
example/ios/Frameworks/
example/lib/ui/

.vscode/
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 1.0.22

## 1.0.21
LiveQuery fix
Logout fix
Expand Down
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Want to get involved? Join our Slack channel and help out! (http://flutter-parse
To install, either add to your pubspec.yaml
```yml
dependencies:
parse_server_sdk: ^1.0.21
parse_server_sdk: ^1.0.22
```
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.

Expand Down Expand Up @@ -163,9 +163,9 @@ var response = await dietPlan.remove("listKeywords", ["a"]);
or using with save function

```dart
dietPlan.setAdd('listKeywords', ['a','a','d']);
dietPlan.setAddUnique('listKeywords', ['a','a','d']);
dietPlan.setRemove('listKeywords', ['a']);
dietPlan.setAddAll('listKeywords', ['a','a','d']);
dietPlan.setAddAllUnique('listKeywords', ['a','a','d']);
dietPlan.setRemoveAll('listKeywords', ['a']);
var response = dietPlan.save()
```

Expand Down Expand Up @@ -539,6 +539,21 @@ final Map<String, String> params = <String, String>{'plan': 'paid'};
function.execute(parameters: params);
```

## Relation
The SDK supports Relation.

To Retrive a relation instance for user, call:
```dart
final relation = user.getRelation('dietPlans');
```

and then you can add a relation to the passed in object.

```dart
relation.add(dietPlan);
final result = await user.save();
```

## Other Features of this library
Main:
* Installation (View the example application)
Expand Down
4 changes: 2 additions & 2 deletions example/lib/data/repositories/user/provider_db_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class UserProviderDB implements UserProviderContract {

Map<String, dynamic> convertItemToStorageMap(User item) {
final Map<String, dynamic> values = Map<String, dynamic>();
// ignore: invalid_use_of_protected_member
values['value'] = json.jsonEncode(item.toJson(full: true));
values[keyVarObjectId] = item.objectId;
item.updatedAt != null
Expand All @@ -90,8 +91,7 @@ class UserProviderDB implements UserProviderContract {
User convertRecordToItem({Record record, Map<String, dynamic> values}) {
try {
values ??= record.value;
final User item =
User.clone().fromJson(json.jsonDecode(values['value']));
final User item = User.clone().fromJson(json.jsonDecode(values['value']));
return item;
} catch (e) {
return null;
Expand Down
96 changes: 54 additions & 42 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:flutter_plugin_example/data/repositories/diet_plan/repository_di
import 'package:flutter_plugin_example/data/repositories/user/repository_user.dart';
import 'package:flutter_plugin_example/domain/constants/application_constants.dart';
import 'package:flutter_plugin_example/domain/utils/db_utils.dart';
import 'package:flutter_plugin_example/pages/decision_page.dart';
import 'package:flutter_stetho/flutter_stetho.dart';
import 'package:parse_server_sdk/parse_server_sdk.dart';

Expand Down Expand Up @@ -41,69 +40,82 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
DietPlanRepository dietPlanRepo;
UserRepository userRepo;

String text = '';

@override
void initState() {
super.initState();
// initData();
initData();
}

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text(text),
),
title: 'Parse Server Example',
home: DecisionPage());
),
);
}

Future<void> initData() async {
// Initialize repository
// await initRepository();
await initRepository();

// Initialize parse
Parse().initialize(keyParseApplicationId, keyParseServerUrl,
masterKey: keyParseMasterKey, debug: true);

//parse serve with secure store and desktop support

// Parse().initialize(keyParseApplicationId, keyParseServerUrl,
// masterKey: keyParseMasterKey,
// debug: true,
// coreStore: CoreStoreImp.getInstance());
// Parse().initialize(keyParseApplicationId, keyParseServerUrl,
// masterKey: keyParseMasterKey,
// debug: true,
// coreStore: CoreStoreImp.getInstance());

// Check server is healthy and live - Debug is on in this instance so check logs for result
final ParseResponse response = await Parse().healthCheck();

if (response.success) {
await runTestQueries();
print('runTestQueries');
text += 'runTestQueries\n';
print(text);
} else {
print('Server health check failed');
text += 'Server health check failed';
print(text);
}
}

Future<void> runTestQueries() async {
// Basic repository example
//await repositoryAddUser();
//await repositoryAddItems();
//await repositoryGetAllItems();
await repositoryAddUser();
await repositoryAddItems();
await repositoryGetAllItems();

//Basic usage
// createItem();
// getAllItems();
// getAllItemsByName();
// getSingleItem();
// getConfigs();
// query();
// initUser();
// var instalattion = await ParseInstallation.currentInstallation();
// var rees = instalattion.create();
// print(rees);
//function();
//functionWithParameters();
// test();
await createItem();
await getAllItems();
await getAllItemsByName();
await getSingleItem();
await getConfigs();
await query();
await initUser();
await initInstallation();
await function();
await functionWithParameters();
await test();
}

Future<void> initInstallation() async {
final ParseInstallation installation =
await ParseInstallation.currentInstallation();
final ParseResponse response = await installation.create();
print(response);
}

Future<void> test() async {
Expand Down Expand Up @@ -240,13 +252,13 @@ class _MyAppState extends State<MyApp> {
/// Update current user from server - Best done to verify user is still a valid user
response = await ParseUser.getCurrentUserFromServer(
token: user?.get<String>(keyHeaderSessionToken));
if (response.success) {
if (response?.success ?? false) {
user = response.result;
}

/// log user out
response = await user.logout();
if (response.success) {
response = await user?.logout();
if (response?.success ?? false) {
user = response.result;
}

Expand Down Expand Up @@ -359,13 +371,13 @@ class _MyAppState extends State<MyApp> {
dietPlanRepo ??= DietPlanRepository.init(await getDB());
userRepo ??= UserRepository.init(await getDB());
}

String dietPlansToAdd =
'[{"className":"Diet_Plans","Name":"Textbook","Description":"For an active lifestyle and a straight forward macro plan, we suggest this plan.","Fat":25,"Carbs":50,"Protein":25,"Status":0},'
'{"className":"Diet_Plans","Name":"Body Builder","Description":"Default Body Builders Diet","Fat":20,"Carbs":40,"Protein":40,"Status":0},'
'{"className":"Diet_Plans","Name":"Zone Diet","Description":"Popular with CrossFit users. Zone Diet targets similar macros.","Fat":30,"Carbs":40,"Protein":30,"Status":0},'
'{"className":"Diet_Plans","Name":"Low Fat","Description":"Low fat diet.","Fat":15,"Carbs":60,"Protein":25,"Status":0},'
'{"className":"Diet_Plans","Name":"Low Carb","Description":"Low Carb diet, main focus on quality fats and protein.","Fat":35,"Carbs":25,"Protein":40,"Status":0},'
'{"className":"Diet_Plans","Name":"Paleo","Description":"Paleo diet.","Fat":60,"Carbs":25,"Protein":10,"Status":0},'
'{"className":"Diet_Plans","Name":"Ketogenic","Description":"High quality fats, low carbs.","Fat":65,"Carbs":5,"Protein":30,"Status":0}]';
}

const String dietPlansToAdd =
'[{"className":"Diet_Plans","Name":"Textbook","Description":"For an active lifestyle and a straight forward macro plan, we suggest this plan.","Fat":25,"Carbs":50,"Protein":25,"Status":0},'
'{"className":"Diet_Plans","Name":"Body Builder","Description":"Default Body Builders Diet","Fat":20,"Carbs":40,"Protein":40,"Status":0},'
'{"className":"Diet_Plans","Name":"Zone Diet","Description":"Popular with CrossFit users. Zone Diet targets similar macros.","Fat":30,"Carbs":40,"Protein":30,"Status":0},'
'{"className":"Diet_Plans","Name":"Low Fat","Description":"Low fat diet.","Fat":15,"Carbs":60,"Protein":25,"Status":0},'
'{"className":"Diet_Plans","Name":"Low Carb","Description":"Low Carb diet, main focus on quality fats and protein.","Fat":35,"Carbs":25,"Protein":40,"Status":0},'
'{"className":"Diet_Plans","Name":"Paleo","Description":"Paleo diet.","Fat":60,"Carbs":25,"Protein":10,"Status":0},'
'{"className":"Diet_Plans","Name":"Ketogenic","Description":"High quality fats, low carbs.","Fat":65,"Carbs":5,"Protein":30,"Status":0}]';
2 changes: 1 addition & 1 deletion example/lib/pages/decision_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class _DecisionPageState extends State<DecisionPage> {
final MaterialPageRoute<bool> newRoute =
MaterialPageRoute<bool>(builder: (BuildContext context) => page);

bool nav = await Navigator.of(context)
final bool nav = await Navigator.of(context)
.pushAndRemoveUntil<bool>(newRoute, ModalRoute.withName('/'));
if (nav == true) {
_initParse();
Expand Down
21 changes: 11 additions & 10 deletions example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import 'package:flutter_plugin_example/data/repositories/diet_plan/contract_prov
import 'package:parse_server_sdk/parse_server_sdk.dart';

class HomePage extends StatefulWidget {
HomePage(this._dietPlanProvider);
const HomePage(this._dietPlanProvider);

final DietPlanProviderContract _dietPlanProvider;

@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
List<DietPlan> randomDietPlans = [];
List<DietPlan> randomDietPlans = <DietPlan>[];

@override
void initState() {
Expand Down Expand Up @@ -50,9 +51,9 @@ class _HomePageState extends State<HomePage> {
body: _showDietList(),
floatingActionButton: FloatingActionButton(
onPressed: () async {
DietPlan dietPlan =
final DietPlan dietPlan =
randomDietPlans[Random().nextInt(randomDietPlans.length - 1)];
ParseUser user = await ParseUser.currentUser();
final ParseUser user = await ParseUser.currentUser();
dietPlan.set('user', user);
await widget._dietPlanProvider.add(dietPlan);
setState(() {});
Expand Down Expand Up @@ -80,15 +81,15 @@ class _HomePageState extends State<HomePage> {
shrinkWrap: true,
itemCount: snapshot.data.results.length,
itemBuilder: (BuildContext context, int index) {
DietPlan dietPlan = snapshot.data.results[index];
String id = dietPlan.objectId;
String name = dietPlan.name;
String description = dietPlan.description;
bool status = dietPlan.status;
final DietPlan dietPlan = snapshot.data.results[index];
final String id = dietPlan.objectId;
final String name = dietPlan.name;
final String description = dietPlan.description;
final bool status = dietPlan.status;
return Dismissible(
key: Key(id),
background: Container(color: Colors.red),
onDismissed: (direction) async {
onDismissed: (DismissDirection direction) async {
widget._dietPlanProvider.remove(dietPlan);
},
child: ListTile(
Expand Down
22 changes: 11 additions & 11 deletions example/lib/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LoginPage extends StatefulWidget {
}

class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

String _email;
String _password;
Expand All @@ -22,7 +22,7 @@ class _LoginPageState extends State<LoginPage> {

// Check if form is valid before perform login or signup
bool _validateAndSave() {
final form = _formKey.currentState;
final FormState form = _formKey.currentState;
if (form.validate()) {
form.save();
return true;
Expand All @@ -33,11 +33,11 @@ class _LoginPageState extends State<LoginPage> {
// Perform login or signup
Future<void> _validateAndSubmit() async {
setState(() {
_errorMessage = "";
_errorMessage = '';
_isLoading = true;
});
if (_validateAndSave()) {
User user = User(_email, _password, _email);
final User user = User(_email, _password, _email);

ParseResponse response;
try {
Expand Down Expand Up @@ -73,22 +73,22 @@ class _LoginPageState extends State<LoginPage> {

@override
void initState() {
_errorMessage = "";
_errorMessage = '';
_isLoading = false;
super.initState();
}

void _changeFormToSignUp() {
_formKey.currentState.reset();
_errorMessage = "";
_errorMessage = '';
setState(() {
_formMode = FormMode.SIGNUP;
});
}

void _changeFormToLogin() {
_formKey.currentState.reset();
_errorMessage = "";
_errorMessage = '';
setState(() {
_formMode = FormMode.LOGIN;
});
Expand Down Expand Up @@ -185,8 +185,8 @@ class _LoginPageState extends State<LoginPage> {
Icons.mail,
color: Colors.grey,
)),
validator: (value) => value.isEmpty ? 'Email can\'t be empty' : null,
onSaved: (value) => _email = value,
validator: (String value) => value.isEmpty ? 'Email can\'t be empty' : null,
onSaved: (String value) => _email = value,
),
);
}
Expand All @@ -204,8 +204,8 @@ class _LoginPageState extends State<LoginPage> {
Icons.lock,
color: Colors.grey,
)),
validator: (value) => value.isEmpty ? 'Password can\'t be empty' : null,
onSaved: (value) => _password = value,
validator: (String value) => value.isEmpty ? 'Password can\'t be empty' : null,
onSaved: (String value) => _password = value,
),
);
}
Expand Down
17 changes: 9 additions & 8 deletions example/windows/find_vcvars.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
import 'dart:io';

int main() {
final programDir = Platform.environment['PROGRAMFILES(X86)'];
final pathPrefix = '$programDir\\Microsoft Visual Studio';
const pathSuffix = 'VC\\Auxiliary\\Build\\vcvars64.bat';
final years = ['2017', '2019'];
final flavors = ['Community', 'Professional', 'Enterprise', 'Preview'];
for (final year in years) {
for (final flavor in flavors) {
final testPath = '$pathPrefix\\$year\\$flavor\\$pathSuffix';
final String programDir = Platform.environment['PROGRAMFILES(X86)'];
final String pathPrefix = '$programDir\\Microsoft Visual Studio';
const String pathSuffix = 'VC\\Auxiliary\\Build\\vcvars64.bat';
final List<String> years = <String>['2017', '2019'];
final List<String> flavors = <String>[
'Community', 'Professional', 'Enterprise', 'Preview'];
for (final String year in years) {
for (final String flavor in flavors) {
final String testPath = '$pathPrefix\\$year\\$flavor\\$pathSuffix';
if (File(testPath).existsSync()) {
print(testPath);
return 0;
Expand Down
Loading