1. plugin apis
  2. forms

Forms

Documentation for the Forms API for spotube plugins

Spotube provides a Forms API that allows plugin developers to create and manage forms within the Spotube application.

Following will show a form with 2 text fields and text in between them:

import "module:spotube_plugin" as spotube

spotube.SpotubeForm.show(
  "The form page title",
  [
    {
      objectType: "input",
      id: "name",
      variant: "text",
      placeholder: "Enter your name",
      required: true,
    }.toJson(),
    {
      objectType: "input",
      id: "password",
      variant: "password", // This will obfuscate the input
      placeholder: "Enter your password",
      required: true,
    }.toJson(),
    {
      objectType: "text",
      text: "This is some text after the two fields.",
    }.toJson(),
  ]
).then((result) {
  // Handle the result
  print(result)
})

The method spotube.SpotubeForm.show takes a title and a list of form field declaration map. The map should be, well obviously a Map. Following are field map properties:

PropertyTypeDescription
objectTypetext or inputType of the object, should be text for text fields and input for input fields.
idStringUnique identifier for the field. (input type only)
variantStringVariant of the field, can be text, password or number. (input type only)
placeholderStringOptional placeholder text for the field. (input type only)
requiredBooleanWhether the field is required or not. (input type only)
defaultValueStringOptional default value for the field. (input type only)
regexStringOptional regex pattern to validate the input. (input type only)
textStringOptional text for text object type. (Only applicable for text type)

The method spotube.SpotubeForm.show returns a following format:

[
  {
    "id": "name",
    "value": "John Doe"
  },
  {
    "id": "password",
    "value": "12345678"
  }
]