publishSchema method Null safety

Future<CreateSchemaResponse> publishSchema(
  1. String label,
  2. Map<String, SchemaKind> fields,
  3. {Map<String, String>? metadata}
)

Publish 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

Implementation

Future<CreateSchemaResponse> publishSchema(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<CreateSchemaResponse>();
  }
  return resp;
}