buildTextField method

Widget buildTextField(
  1. BuildContext context
)

Implementation

Widget buildTextField(BuildContext context) {
  String? title = widget.schema["title"];
  dynamic description = widget.schema["description"];
  String? helperText = widget.schema["helperText"];
  String? placeholder = widget.schema["placeholder"];
  int? minLines = widget.schema["minLines"];
  int? maxLines = widget.schema["maxLines"];
  bool? hideLabel = widget.schema["hideLabel"];

  return Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      title != null ? Text(title) : Container(),
      title != null ? const SizedBox(height: 8) : Container(),
      TextField(
        keyboardType: TextInputType.multiline,
        minLines: minLines,
        maxLines: maxLines,
        controller: _controller,
        enabled: widget.options?["readonly"] != true,
        obscureText: widget.options?["secret"] == true && !showSecret,
        onChanged: ((val) {
          onValueChanged(val);
        }),
        textAlign: TextAlign.start,
        textAlignVertical: TextAlignVertical.center,
        maxLength: _maxLength,
        decoration: InputDecoration(
          errorText: errorText(),
          border: const UnderlineInputBorder(),
          labelText: hideLabel == true ? null : widget.label.titleCase,
          counterText: "",
          helperText: helperText,
          hintText: placeholder,
          contentPadding: const EdgeInsets.all(2),
          suffixIcon: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              widget.options?["secret"] == true
                  ? IconButton(
                      icon: Icon(
                        showSecret ? Icons.visibility : Icons.visibility_off,
                      ),
                      tooltip: showSecret ? "Hide" : "Show",
                      splashRadius: 12,
                      iconSize: 18,
                      onPressed: () {
                        setState(() {
                          showSecret = !showSecret;
                        });
                      },
                    )
                  : Container(),
              IconButton(
                icon: const Icon(Icons.close),
                tooltip: value.isEmpty ? null : "Clear",
                splashRadius: 12,
                iconSize: 18,
                onPressed: value.isEmpty
                    ? null
                    : () {
                        onValueChanged("");
                        _controller.text = "";
                      },
              ),
            ],
          ),
        ),
      ),
      description != null ? const SizedBox(height: 8) : Container(),
      description != null
          ? MarkdownBody(
              data: description["text"],
              onTapLink: (text, href, title) {
                launchUrl(Uri.parse(href!));
              },
              styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context))
                  .copyWith(
                      p: Theme.of(context)
                          .textTheme
                          .headline1
                          ?.copyWith(fontSize: description["size"] ?? 14.0)),
            )
          : Container(),
    ],
  );
}