Skip to content

Commit 5465970

Browse files
authored
feat: Add Parse Flutter SDK documentation (#928)
1 parent 109dbe8 commit 5465970

21 files changed

+4162
-2
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ node_modules
1616
# OS X
1717
.DS_Store
1818

19+
# IntelliJ related
20+
*.iml
21+
*.ipr
22+
*.iws
23+
.idea/
24+
1925
.jekyll-metadata

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ apis:
2323
js: https://parseplatform.org/Parse-SDK-JS/api/master/
2424
php: https://parseplatform.org/parse-php-sdk/namespaces/Parse.html
2525
dotnet: https://parseplatform.org/Parse-SDK-dotNET/api/
26+
flutter: https://parseplatform.org/Parse-SDK-Flutter/api/
2627
parse-server: https://parseplatform.org/parse-server/api/
2728

2829
# Build settings

_includes/flutter/cloud-code.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Cloud Code
2+
3+
The SDK supports calling [Cloud Functions](https://docs.parseplatform.org/cloudcode/guide/#cloud-functions).
4+
5+
Execute a Cloud Function that returns a `ParseObject`:
6+
7+
```dart
8+
final ParseCloudFunction function = ParseCloudFunction('hello');
9+
final ParseResponse result =
10+
await function.executeObjectFunction<ParseObject>();
11+
if (result.success) {
12+
if (result.result is ParseObject) {
13+
final ParseObject parseObject = result.result;
14+
print(parseObject.className);
15+
}
16+
}
17+
```
18+
19+
Execute a Cloud Function with parameters:
20+
21+
```dart
22+
final ParseCloudFunction function = ParseCloudFunction('hello');
23+
final Map<String, String> params = <String, String>{'plan': 'paid'};
24+
function.execute(parameters: params);
25+
```

_includes/flutter/config.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Config
2+
3+
The SDK supports [Parse Config](https://docs.parseplatform.org/cloudcode/guide/#config). A map of config parameters can be retrieved from Parse Server with:
4+
5+
```dart
6+
var response = await ParseConfig().getConfigs();
7+
```
8+
9+
To add a new parameter to Parse Config:
10+
11+
```dart
12+
ParseConfig().addConfig('TestConfig', 'testing');
13+
```

_includes/flutter/files.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Files
2+
3+
There are three different file classes in this SDK:
4+
5+
- `ParseFileBase` is an abstract class and is the foundation of every file class that can be handled by the SDK.
6+
- `ParseFile` extends `ParseFileBase` and is by default used as the file class on every platform but web. This class uses a `File` from `dart:io` for storing the raw file. The class was formerly the only file class in the SDK.
7+
- `ParseWebFile` is the equivalent of `ParseFile` used for Flutter Web. This class uses a `Uint8List` for storing the raw file data.
8+
9+
The classes above are used by default to represent files, but you can also build your own class extending `ParseFileBase` and provide a custom `ParseFileConstructor` similar to the `SubClasses`.
10+
11+
Have a look at the example application for a small (non web) example.
12+
13+
When uploading or downloading a file, you can use the `progressCallback` parameter to track the progress of the HTTP request.
14+
15+
The following is an example for showing an image from a `ParseFileBase`:
16+
17+
```dart
18+
Widget buildImage(ParseFileBase image){
19+
return FutureBuilder<ParseFileBase>(
20+
future: image.download(),
21+
builder: (BuildContext context,
22+
AsyncSnapshot<ParseFileBase> snapshot) {
23+
if (snapshot.hasData) {
24+
if (kIsWeb) {
25+
return Image.memory((snapshot.data as ParseWebFile).file);
26+
} else {
27+
return Image.file((snapshot.data as ParseFile).file);
28+
}
29+
} else {
30+
return CircularProgressIndicator();
31+
}
32+
},
33+
);
34+
}
35+
```
36+
37+
A short example for storing a selected image:
38+
39+
```dart
40+
// Libraries: image_picker (https://pub.dev/packages/image_picker), image_picker_for_web (https://pub.dev/packages/image_picker_for_web)
41+
PickedFile pickedFile = await ImagePicker().getImage(source: ImageSource.gallery);
42+
43+
ParseFileBase parseFile;
44+
45+
if (kIsWeb) {
46+
// Get data from selected file as an Uint8List
47+
ParseWebFile file = ParseWebFile(null, name: null, url: pickedFile.path);
48+
await file.download();
49+
parseFile = ParseWebFile(file.file, name: file.name);
50+
} else {
51+
parseFile = ParseFile(File(pickedFile.path));
52+
}
53+
54+
someParseObject.set("image", parseFile);
55+
// Save ParseObject and its children like the ParseFileBase
56+
await someParseObject.save();
57+
```
58+
59+
Example for using the progress callback:
60+
61+
```dart
62+
file.upload(progressCallback: (int count, int total) => print("$count of $total"));
63+
```

_includes/flutter/getting-started.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Getting Started
2+
3+
- To install the Parse Dart SDK add it to your app as a dependency via the [pub.dev](https://pub.dev/packages/parse_server_sdk/install) registry.
4+
- To install the Parse Flutter SDK add it to your app as a dependency via the [pub.dev](https://pub.dev/packages/parse_server_sdk_flutter/install) registry.
5+
6+
Once you have the SDK added as a dependency, initialize the SDK as early as possible in your application (e.g. in your application class) like this:
7+
8+
```dart
9+
await Parse().initialize(
10+
keyApplicationId,
11+
keyParseServerUrl,
12+
);
13+
```
14+
15+
If you want to use secure storage or use the Flutter web/desktop SDK, please change to the below instance of `CoreStorage` as it has no dependencies on Flutter. `CoreStoreSembastImp` does not encrypt the data on the web and Web is not safe anyway. Encrypt fields manually as needed.
16+
17+
```dart
18+
await Parse().initialize(
19+
keyParseApplicationId,
20+
keyParseServerUrl,
21+
coreStore: await CoreStoreSembastImp.getInstance("/data"));
22+
```
23+
24+
It's possible to add other parameters to work with your instance of Parse Server:
25+
26+
```dart
27+
await Parse().initialize(
28+
keyApplicationId,
29+
keyParseServerUrl,
30+
clientKey: keyParseClientKey, // Required for some setups
31+
debug: true, // When enabled, prints logs to console
32+
liveQueryUrl: keyLiveQueryUrl, // Required if using LiveQuery
33+
autoSendSessionId: true, // Required for authentication and ACL
34+
securityContext: securityContext, // Again, required for some setups
35+
coreStore: CoreStoreMemoryImp()); // Non persistent mode (default): Sdk will store everything in memory instead of using Sembast as an internal DB.
36+
```
37+
38+
⚠️ The master key should only be used in safe environments and never on client side. Using this package on a server should be fine.
39+
40+
### Early Web Support
41+
42+
Due to Cross-Origin Resource Sharing (CORS) restrictions, web support requires adding `X-Parse-Installation-Id` as an allowed header in the Parse Server configuration:
43+
44+
- When running directly via docker, set the env var `PARSE_SERVER_ALLOW_HEADERS=X-Parse-Installation-Id`.
45+
- When running via express, set the [Parse Server option](https://parseplatform.org/parse-server/api/master/ParseServerOptions.html) `allowHeaders: ['X-Parse-Installation-Id']`.
46+
47+
### Desktop Support (macOS)
48+
49+
The security entitlements posed by the macOS framework require that your app is granted permission to open outgoing network connections, so that the Parse Flutter SDK can communicate with Parse Server. To grant this permission, add the following code:
50+
51+
```swift
52+
<key>com.apple.security.network.client</key>
53+
<true/>
54+
```
55+
56+
to the following files:
57+
58+
```
59+
/macOS/Runner/Release.entitlements
60+
/macOS/Runner/DebugProfile.entitlements
61+
```
62+
63+
### Network client
64+
65+
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.
66+
67+
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:
68+
69+
```dart
70+
await Parse().initialize(
71+
//...
72+
clientCreator: ({bool? sendSessionId, SecurityContext? securityContext}) => ParseDioClient(sendSessionId: sendSessionId, securityContext: securityContext),
73+
);
74+
```

0 commit comments

Comments
 (0)