candid_dart_build 1.1.4 candid_dart_build: ^1.1.4 copied to clipboard
Provides [Dart Build System](https://github.com/dart-lang/build) builders for handling `.did` files and quickly generate Dart code corresponding to `.did` files.
Candid Dart Build #
English | 简体中文
Provides Dart Build System builders for handling .did
files and quickly generate
Dart code corresponding to .did
files.
The generated code includes:
IDL
Service
and related methods- Objects and related methods corresponding to
.did
files
The generated code depends on agent_dart
Quick start #
Introduction of dependencies #
- Execute the following command (recommended)
# With Dart
dart pub add --dev candid_dart_build
dart pub add --dev build_runner
# With Flutter
flutter pub add --dev candid_dart_build
flutter pub add --dev build_runner
- Manually add it to the
pubspec.yaml
under the project
dev_dependencies:
candid_dart_build: any
build_runner: any
Run the generator #
# With Dart
dart run build_runner build
# With Flutter
flutter pub run build_runner build
Configuration #
targets:
$default:
builders:
candid_dart_build|candid2dart:
options:
# Whether to use Freezed, default is `false`
freezed: false
# Whether to generate the `copyWith` method, default is `true`
copy_with: true
# Whether to generate the `equals` and `hashCode` methods, default is `true`
equal: true
# Whether collection fields are unmodifiable, only effective when Freezed is turned on, default is `true`
make_collections_unmodifiable: true
# Is `Service` generated automatically?
service: true
# Import packages with settings into each generated Dart file.
inject_packages:
- package:recase/recase.dart
- package:dart_style/dart_style.dart
# Inject a piece of code before calling the Actor method, which can reference the request parameters `request` and the parameter of type CanisterActor `actor`.
pre_actor_call: |
print(method);
print(request);
print(actor);
// ...
# Inject a piece of code after calling the Actor method, which can reference the request parameters `request`, the parameter of type CanisterActor `actor`, and the return result of the method `response`.
post_actor_call: |
print(method);
print(request);
print(actor);
print(response);
// ...
Example #
Please see the example project.
License #
MIT License
Copyright (c) 2022 AstroxNetwork
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.