|
| 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