Example of using Amplify DataStore in a Flutter mobile app. The goal of this example is to show how to provide a temporary Flutter DataStore solution that can be used until one is provided by the real Amplify Flutter SDK.
The solution is implemented as a Flutter platform plugin that lives alongside the Amplify Flutter (Developer Preview). Underneath, it registers the native Android or iOS Amplify DataStore, and Api plugins. Then exposes a DataStore-like interface to the Flutter Dart code using method and event channels.
This example is not a generic DataStore solution for Flutter. Native Android and iOS DataStore implementations rely on being able to locate model classes generated with amplify codegen models
. Therefore, each time you update the GraphQL schema you will need to regenerate the Android and iOS platform specific models. You will also need to hand-code the Flutter DataStore models since the Amplify CLI does not currently support DataStore.
To demonstrate that the example plugin interoperates alongside the Amplify Flutter developer preview it has Cognito authorization enabled on the GraphQL API. Therefore, on first use, it requires the user to create an account, or sign in.
To run this example you will need to use the Amplify CLI to deploy the backend services into your AWS account. This will generate an amplifyconfiguration.dart
file which can then be used to build the example Flutter app.
-
If you don't have it already, install the Amplify-Flutter Developer Preview version of the Amplify CLI by running:
npm install -g @aws-amplify/cli@flutter-preview
-
Clone this repository. Ex:
git clone https://github.com/kjones/flutter-datastore-example.git
-
Deploy the backend Amplify services into your AWS account.
cd flutter-datastore-example/example amplify init
Optional: You can list the Amplify services that will get created during the
amplify push
stage if you are curious. The following should show thatAuth
, andApi
services will get created.amplify status
Deploy the Amplify services. When asked, "Do you want to generate code for your newly created GraphQL API (Y/n)", answer "No" since the Amplify CLI does not yet support GraphQL Flutter code generation.
amplify push
- Run Android Studio and open the example plugin project from the root of the cloned repository.
- Run Flutter Pub Get.
- Start and Select a device or emulator (see Flutter docs)
- Run the app.
From the example app folder, delete the Amplify services.
cd example
amplify delete