createSchema method Null safety
{@subCategory Create a Schema Definition On-Chain}
Builds a request for recording a SchemaDefinition
on the blockchain. metadata
is for any additional information that should be stored with the schema. callback
is an optional
function that will be called when the transaction is complete. Returns a CreateSchemaResponse
if the transaction is successful.
final res = await MotorFlutter.to.createSchema('My Schema', {'name': SchemaKind.STRING, 'age': SchemaKind.INT});
if (res == null) {
throw Exception('Failed to create schema');
}
Next Steps
- Build a SchemaDocument from a Definition with SchemaDefinitionExt
- ADR-3
Implementation
Future<CreateSchemaResponse> createSchema(String label, Map<String, SchemaKind> fields, {Map<String, String>? metadata}) async {
final resp = await MotorFlutterPlatform.instance.createSchema(CreateSchemaRequest(
label: label,
fields: fields,
metadata: metadata,
));
if (resp == null) {
throw UnmarshalException<CreateAccountResponse>();
}
return resp;
}