buildDatePicker method

Widget buildDatePicker(
  1. BuildContext context
)

Implementation

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

  return Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      title != null ? Text(title) : Container(),
      title != null ? const SizedBox(height: 8) : Container(),
      TextField(
        controller: _controller,
        onTap: () async {},
        readOnly: true,
        enabled: widget.options?["readonly"] != true,
        decoration: InputDecoration(
          labelText: hideLabel == true ? null : widget.label.titleCase,
          hintText: placeholder ?? "dd.MM.yyyy",
          helperText: helperText,
          contentPadding: const EdgeInsets.all(2),
          suffixIcon: IconButton(
            icon: const Icon(Icons.calendar_today),
            tooltip: "Select",
            splashRadius: 24,
            iconSize: 18,
            onPressed: widget.options?["readonly"] == true
                ? null
                : () async {
                    DateTime? picked = await showDatePicker(
                      context: context,
                      initialDate: DateTime.now(),
                      firstDate: DateTime(1900),
                      lastDate: DateTime(2099),
                    );

                    if (picked == null) {
                      return;
                    }

                    String val = _dateFormat.format(picked);
                    onValueChanged(val);
                    _controller.text = val;
                  },
          ),
        ),
      ),
      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(),
    ],
  );
}