pocketbase_utils 0.1.6 copy "pocketbase_utils: ^0.1.6" to clipboard
pocketbase_utils: ^0.1.6 copied to clipboard

pocketbase_utils is a dart library that generates Dart models code from a PocketBase collections scheme json file.

PocketBase Utils #

pub package

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.

Usage #

You can use this package directly through the command line on any device with Dart installed.

Follow these steps to get started:

1. Download the collections schema #

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

2. Install the package #

Add the package into your pubspec.yaml:

...
dev_dependencies:
    ...
    pocketbase_utils: x.x.x

Or instead of installing it to your dev_dependencies you can just use the dart pub global:

dart pub global activate pocketbase_utils

You also may have to install the build_runner,json_serializable, equatable, collection, and pocketbase packages.

3. Configure package #

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
  generate_system_collections: false # Optional. Generate models for the system level collections like `_mfas`, `_otps`, and `_superusers`. Default: false

4. Run the generator #

In the root of your flutter project run:

dart run pocketbase_utils:generate

Or if you used the dart pub global activate:

pbutil-gen

⬆️ If this doesn't work, you might need to set up your path.

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

Contributing #

Contributions are welcome! Please create an issue or make a fork and propose a PR to contribute to this project.

Commands #

Publish package #

dart pub publish --dry-run

Generate code inside the package #

dart run build_runner build --delete-conflicting-outputs

License #

This project is licensed under the Apache License 2.0.

6
likes
140
points
120
downloads

Publisher

unverified uploader

Weekly Downloads

pocketbase_utils is a dart library that generates Dart models code from a PocketBase collections scheme json file.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

analyzer, args, code_builder, collection, dart_style, json_annotation, path, petitparser, recase, yaml

More

Packages that depend on pocketbase_utils