amplify-flutter-datastore-extension
v0.2.3
Published
amplify plugin to generate Flutter Extensions for DataStore operations.
Downloads
8
Maintainers
Readme
About The Project
This project is amplify plugin to generate Flutter Extensions for DataStore operations.
This feature is automatically executed when run amplify codegen models
.
Getting Started
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
Prerequisites
First, install AWS Amplify CLI using npm (we assume you have pre-installed node.js).
npm install -g @aws-amplify/cli
Installation
- Install NPM packages
npm install -g amplify-flutter-datastore-extension
- Enable this plugin
amplify plugin add $(npm root -g)/amplify-flutter-datastore-extension
Usage
amplify/backend/api/{api_name}/schema.graphql
containing the following:
type Todo @model {
id: ID!
name: String!
description: String
}
Run the following command:
amplify codegen models
The plugin outputs DataStoreExtension.dart
with the following contents:
import 'ModelProvider.dart';
import 'package:amplify_core/amplify_core.dart' as amplify_core;
/** This is an auto generated extension representing the Todo type in your schema. */
extension TodoExtension on amplify_core.DataStoreCategory {
Future<Todo> getTodo(String id) {
return query(
Todo.classType,
where: Todo.MODEL_IDENTIFIER.eq(TodoModelIdentifier(id: id)),
)
.then((list) => list.single);
}
Future<Todo?> getTodoOrNull(String id) {
return query(
Todo.classType,
where: Todo.MODEL_IDENTIFIER.eq(TodoModelIdentifier(id: id)),
)
.then((list) => list.singleOrNull);
}
}
You can call it as follows:
final id = "080f33bf-0362-4c7f-9dfa-de64fc231dca";
final todo = await Amplify.DataStore.getTodo(id);
Roadmap
See the open issues for a list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the Apache-2.0 License. See LICENSE
for more information.
Contact
Masahiko MURAKAMI - @fossamagna
Project Link: https://github.com/fossamagna/amplify-flutter-datastore-extension