Dart package that creates a binding between your pocketbase server and your Flutter app by generating typesafe boilerplate code of your collections from pb_schema.json
file.
You can use this package directly through the command line on any device with Dart installed.
Follow these steps to get started:
- Open your pocketbase admin panel and go to
Settings/Export collections
. - Click on "Download as JSON" button.
- Save the file into the project (the root is default by the config).
Reminder
: You may also want to add your file into the.gitignore
.
Add the package into your pubspec.yaml
:
...
dev_dependencies:
...
pocketbase_utils: x.x.x
You also may have to install the json_serializable, equatable, collection, and pocketbase packages.
Add package configuration to your pubspec.yaml
file. Here is a full configuration for the package:
---
pocketbase_utils:
enabled: true # Required. Must be set to true to activate the package. Default: false
pb_schema_path: pb_schema.json # Optional. Sets the path of your collection schema file. Default: pb_schema.json
output_dir: lib/generated/pocketbase # Optional. Sets the directory of generated model files. If the directory doesn't exist — it'll be created. Default: lib/generated/pocketbase
line_length: 80 # Optional. Sets the length of line for dart formatter of generated code. Default: 80
In the root of your flutter project run:
dart run pocketbase_utils:generate
This will produce files inside lib/generated/pocketbase
directory.
You can also change the output folder to a custom directory by adding the output_dir
line in your pubspec.yaml
file.
And then to build the toJson
and fromJson
run:
dart run build_runner build --delete-conflicting-outputs
Contributions are welcome! Please create an issue or make a fork and propose a PR to contribute to this project.
dart pub publish --dry-run
dart run build_runner build --delete-conflicting-outputs
This project is licensed under the Apache License 2.0.