-
-
Notifications
You must be signed in to change notification settings - Fork 514
feat: Add Parse Flutter SDK documentation #928
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
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
740e595
add flutter getting-started.md
mbfakourii 394cfb6
add file
mbfakourii d25cf7a
add config
mbfakourii 3ca76de
add cloud-code.md
mbfakourii 9e6dd83
merge with flutter and dart parse sdk doc
mbfakourii b547d76
add flutter in another pages
mbfakourii 14a1c93
Update _includes/flutter/cloud-code.md
mbfakourii 94bf6bb
Update _includes/flutter/cloud-code.md
mbfakourii 9219330
Update _includes/flutter/config.md
mbfakourii d6a4301
Update _includes/flutter/config.md
mbfakourii aea353f
Update _includes/flutter/files.md
mbfakourii c181306
Update _includes/flutter/files.md
mbfakourii afe4085
Update _includes/flutter/files.md
mbfakourii 48616e5
Update _includes/flutter/files.md
mbfakourii 442ab96
Update _includes/flutter/getting-started.md
mbfakourii 558995e
Update _includes/flutter/getting-started.md
mbfakourii 984f00f
add Push Notifications
mbfakourii 6892e6c
cleaning
mbfakourii 1b45734
cleaning
mbfakourii d49e616
cleaning
mbfakourii ade9596
add idea in gitignore
mbfakourii a844086
style fixes
mtrezza 85696ba
Update _includes/flutter/objects.md
mtrezza 479d09e
fix some style issues
mbfakourii 3d7dfd1
fix some style issues
mbfakourii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,10 @@ node_modules | |
# OS X | ||
.DS_Store | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
.jekyll-metadata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Cloud Code | ||
|
||
The SDK supports calling [Cloud Functions](https://docs.parseplatform.org/cloudcode/guide/#cloud-functions). | ||
|
||
Execute a Cloud Function that returns a `ParseObject`: | ||
|
||
```dart | ||
final ParseCloudFunction function = ParseCloudFunction('hello'); | ||
final ParseResponse result = | ||
await function.executeObjectFunction<ParseObject>(); | ||
if (result.success) { | ||
if (result.result is ParseObject) { | ||
final ParseObject parseObject = result.result; | ||
print(parseObject.className); | ||
} | ||
} | ||
``` | ||
|
||
Execute a Cloud Function with parameters: | ||
|
||
```dart | ||
final ParseCloudFunction function = ParseCloudFunction('hello'); | ||
final Map<String, String> params = <String, String>{'plan': 'paid'}; | ||
function.execute(parameters: params); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Config | ||
|
||
The SDK supports [Parse Config](https://docs.parseplatform.org/cloudcode/guide/#config). A map of config parameters can be retrieved from Parse Server with: | ||
mtrezza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```dart | ||
var response = await ParseConfig().getConfigs(); | ||
``` | ||
|
||
To add a new parameter to Parse Config: | ||
|
||
```dart | ||
ParseConfig().addConfig('TestConfig', 'testing'); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Files | ||
|
||
There are three different file classes in this SDK: | ||
mtrezza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- `ParseFileBase` is an abstract class and is the foundation of every file class that can be handled by the SDK. | ||
- `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. | ||
- `ParseWebFile` is the equivalent of `ParseFile` used for Flutter Web. This class uses a `Uint8List` for storing the raw file data. | ||
|
||
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`. | ||
|
||
Have a look at the example application for a small (non web) example. | ||
|
||
When uploading or downloading a file, you can use the `progressCallback` parameter to track the progress of the HTTP request. | ||
|
||
The following is an example for showing an image from a `ParseFileBase`: | ||
|
||
```dart | ||
Widget buildImage(ParseFileBase image){ | ||
return FutureBuilder<ParseFileBase>( | ||
future: image.download(), | ||
builder: (BuildContext context, | ||
AsyncSnapshot<ParseFileBase> snapshot) { | ||
if (snapshot.hasData) { | ||
if (kIsWeb) { | ||
return Image.memory((snapshot.data as ParseWebFile).file); | ||
} else { | ||
return Image.file((snapshot.data as ParseFile).file); | ||
} | ||
} else { | ||
return CircularProgressIndicator(); | ||
} | ||
}, | ||
); | ||
} | ||
``` | ||
|
||
A short example for storing a selected image: | ||
|
||
```dart | ||
// Libraries: image_picker (https://pub.dev/packages/image_picker), image_picker_for_web (https://pub.dev/packages/image_picker_for_web) | ||
PickedFile pickedFile = await ImagePicker().getImage(source: ImageSource.gallery); | ||
|
||
ParseFileBase parseFile; | ||
|
||
if (kIsWeb) { | ||
mtrezza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Get data from selected file as an Uint8List | ||
ParseWebFile file = ParseWebFile(null, name: null, url: pickedFile.path); | ||
await file.download(); | ||
parseFile = ParseWebFile(file.file, name: file.name); | ||
} else { | ||
parseFile = ParseFile(File(pickedFile.path)); | ||
} | ||
|
||
someParseObject.set("image", parseFile); | ||
// Save ParseObject and its children like the ParseFileBase | ||
await someParseObject.save(); | ||
``` | ||
|
||
Example for using the progress callback: | ||
|
||
```dart | ||
file.upload(progressCallback: (int count, int total) => print("$count of $total")); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Getting Started | ||
|
||
- 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. | ||
mtrezza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- 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. | ||
|
||
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: | ||
|
||
```dart | ||
await Parse().initialize( | ||
keyApplicationId, | ||
keyParseServerUrl, | ||
); | ||
``` | ||
|
||
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. | ||
|
||
```dart | ||
await Parse().initialize( | ||
keyParseApplicationId, | ||
keyParseServerUrl, | ||
coreStore: await CoreStoreSembastImp.getInstance("/data")); | ||
``` | ||
|
||
It's possible to add other parameters to work with your instance of Parse Server: | ||
|
||
```dart | ||
await Parse().initialize( | ||
keyApplicationId, | ||
keyParseServerUrl, | ||
clientKey: keyParseClientKey, // Required for some setups | ||
debug: true, // When enabled, prints logs to console | ||
liveQueryUrl: keyLiveQueryUrl, // Required if using LiveQuery | ||
autoSendSessionId: true, // Required for authentication and ACL | ||
securityContext: securityContext, // Again, required for some setups | ||
coreStore: CoreStoreMemoryImp()); // Non persistent mode (default): Sdk will store everything in memory instead of using Sembast as an internal DB. | ||
``` | ||
|
||
⚠️ The master key should only be used in safe environments and never on client side. Using this package on a server should be fine. | ||
|
||
### Early Web Support | ||
|
||
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: | ||
|
||
- When running directly via docker, set the env var `PARSE_SERVER_ALLOW_HEADERS=X-Parse-Installation-Id`. | ||
- When running via express, set the [Parse Server option](https://parseplatform.org/parse-server/api/master/ParseServerOptions.html) `allowHeaders: ['X-Parse-Installation-Id']`. | ||
|
||
### Desktop Support (macOS) | ||
|
||
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: | ||
|
||
```swift | ||
<key>com.apple.security.network.client</key> | ||
<true/> | ||
``` | ||
|
||
to the following files: | ||
|
||
``` | ||
/macOS/Runner/Release.entitlements | ||
/macOS/Runner/DebugProfile.entitlements | ||
``` | ||
|
||
### 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), | ||
); | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.