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

Flutter Guide #865

Draft
wants to merge 6 commits into
base: gh-pages
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions _includes/flutter/analytics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Analytics

Parse provides a number of hooks for you to get a glimpse into the ticking heart of your app. We understand that it's important to understand what your app is doing, how frequently, and when.

While this section will cover different ways to instrument your app to best take advantage of Parse's analytics backend, developers using Parse to store and retrieve data can already take advantage of metrics on Parse.

Without having to implement any client-side logic, you can view real-time graphs and breakdowns (by device type, Parse class name, or REST verb) of your API Requests in your app's dashboard and save these graph filters to quickly access just the data you're interested in.


## Custom Analytics
19 changes: 19 additions & 0 deletions _includes/flutter/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Config


## Save & Update Config


## Retrieving Config



## Internal Config



## Current Config



## Parameters
29 changes: 29 additions & 0 deletions _includes/flutter/files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Files

## Creating a Parse.File



### Client Side


### Server Side


### Embedding files in other objects


## Retrieving File Contents



## Deleting Files



#### Parse Server <4.2.0



## Adding Metadata and Tags

1 change: 1 addition & 0 deletions _includes/flutter/futures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Futures
13 changes: 13 additions & 0 deletions _includes/flutter/geopoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# GeoPoints



## ParseGeoPoint


## Geo Queries



## Caveats

88 changes: 88 additions & 0 deletions _includes/flutter/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Getting Started

To use the parse in your project flutter, start adding the dependency in your project:

You can run flutter command directly in your terminal:

```bash
flutter pub add parse_server_sdk_flutter
```

Then this will add a line like this to your package's pubspec.yaml (and run an implicit `flutter pub get`):

```yaml
dependencies:
parse_server_sdk_flutter: ^3.1.0

```
Alternatively, your editor might support `flutter pub get`. Check the docs for your editor to learn more.


## Initializing the Parse SDK

```dart
import 'package:parse_server_sdk_flutter/generated/i18n.dart';
import 'package:parse_server_sdk_flutter/parse_server_sdk.dart';
import 'dart:async';
import 'package:flutter/material.dart';

void main() async {
final keyParseApplicationId = 'YOUR_APP_ID_HERE';
final keyParseClientKey = 'YOUR_CLIENT_KEY_HERE';
final keyParseServerUrl = 'http://YOUR_PARSE_SERVER:1337/parse';
await Parse().initialize(keyParseApplicationId, keyParseServerUrl,
clientKey: keyParseClientKey);
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter using Parse SDK',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter using Parse SDK'),
),
body: const Center(
child: Text('Hello World'),
),
),
);
}
}
```
Note that you must import the library `dart:async` to use o Parse.

⚠️ If you need to use the master key, note please note that the master key should only be used in safe environments and never on the client-side:

```dart
await Parse().initialize(
//...
masterKey: 'YOUR_MASTERKEY');
```

## Web support

Due to Cross-origin resource sharing (CORS) restrictions, this requires adding `X-Parse-Installation-Id` as an allowed header to parse-server.
When running directly via docker, set the env var `PARSE_SERVER_ALLOW_HEADERS=X-Parse-Installation-Id`.
When running via express, set [ParseServerOptions](https://parseplatform.org/parse-server/api/master/ParseServerOptions.html) `allowHeaders: ['X-Parse-Installation-Id']`.

## Network client

By default, this SDK uses the `ParseHTTPClient`.
Another option is use `ParseDioClient`. This client supports the most features (for example a progress callback at the file upload), but a benchmark has shown, that dio is slower than http on web.

If you want to use the `ParseDioClient`, which uses the dio network library,
you can provide a custom `ParseClientCreator` at the initialization of the SDK.
```dart
await Parse().initialize(
//...
clientCreator: ({bool? sendSessionId, SecurityContext? securityContext}) => ParseDioClient(sendSessionId: sendSessionId, securityContext: securityContext),
);
```



1 change: 1 addition & 0 deletions _includes/flutter/handling-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Error Handling
114 changes: 114 additions & 0 deletions _includes/flutter/live-queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Live Queries

## Standard API
As we discussed in our [LiveQuery protocol](https://github.com/parse-community/parse-server/wiki/Parse-LiveQuery-Protocol-Specification), we maintain a WebSocket connection to communicate with the Parse LiveQuery server. When used server side we use the [`ws`](https://www.npmjs.com/package/ws) package and in the browser we use [`window.WebSocket`](https://developer.mozilla.org/en-US{{ site.baseUrl }}/Web/API/WebSockets_API). We think in most cases it isn't necessary to deal with the WebSocket connection directly. Thus, we developed a simple API to let you focus on your own business logic.

## Create a subscription

```dart
final query = QueryBuilder(ParseObject('Game'));
final LiveQuery liveQuery = LiveQuery();
Subscription subscription = await liveQuery.client.subscribe(query);
```

The subscription you get is actually an event emitter. For more information on event emitter, check [here](https://nodejs.org/api/events.html). You'll get the LiveQuery events through this `subscription`. The first time you call subscribe, we'll try to open the WebSocket connection to the LiveQuery server for you.

## Event Handling
We define several types of events you'll get through a subscription object:

### Open event

Event not available on Flutter SDK.

### Create event

```dart
subscription.on(LiveQueryEvent.create, (value) {
print('object created');
});
```

When a new `ParseObject` is created and it fulfills the `QueryBuilder` you subscribe, you'll get this event. The `object` is the `ParseObject` which was created.

### Update event

```dart
subscription.on(LiveQueryEvent.update, (value) {
print('object updated');
});
```

When an existing `ParseObject` which fulfills the `QueryBuilder` you subscribe is updated (The `ParseObject` fulfills the `QueryBuilder` before and after changes), you'll get this event. The `object` is the `ParseObject` which was updated. Its content is the latest value of the `ParseObject`.

### Enter event

```dart
subscription.on(LiveQueryEvent.enter, (value) {
print('object entered');
});
```

When an existing `ParseObject`'s old value does not fulfill the `QueryBuilder` but its new value fulfills the `QueryBuilder`, you'll get this event. The `object` is the `ParseObject` which enters the `QueryBuilder`. Its content is the latest value of the `ParseObject`.

### Leave event

```dart
subscription.on(LiveQueryEvent.leave, (value) {
print('object left');
});
```

When an existing `ParseObject`'s old value fulfills the `QueryBuilder` but its new value doesn't fulfill the `QueryBuilder`, you'll get this event. The `object` is the `ParseObject` which leaves the `QueryBuilder`. Its content is the latest value of the `ParseObject`.

### Delete event

```dart
subscription.on(LiveQueryEvent.delete, (value) {
print('object deleted');
});
```

When an existing `ParseObject` which fulfills the `QueryBuilder` is deleted, you'll get this event. The `object` is the `ParseObject` which is deleted.

### Close event

Function not available on Flutter SDK.

## Unsubscribe

```dart
liveQuery.client.unSubscribe(subscription);
```

If you would like to stop receiving events from a `QueryBuilder`, you can just unsubscribe the `subscription`. After that, you won't get any events from the `subscription` object.


## Close

Function not available on Flutter SDK.


## Setup server URL

```
Parse().initialize(
keyApplicationId,
keyParseServerUrl,
clientKey: keyParseClientKey,
debug: true,
liveQueryUrl: keyLiveQueryUrl,
autoSendSessionId: true);
```


### Error event

```dart
subscription.on(LiveQueryEvent.delete, (value) {
print('object deleted');
});
```

When some network error or LiveQuery server error happens, you'll get this event.

***
34 changes: 34 additions & 0 deletions _includes/flutter/local-datastore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Local Datastore



## Pinning


## Retrieving



## Querying the Local Datastore



## Unpinning



## Pinning with Labels



## Caching Query Results



## Dumping Contents



## LiveQuery


Loading