formItemBuilder method

Widget formItemBuilder(
  1. BuildContext context,
  2. int index
)

Implementation

Widget formItemBuilder(BuildContext context, int index) {
  RPLocalizations? locale = RPLocalizations.of(context);
  if (index == 0) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 24, left: 8, right: 8, top: 8),
      child: Text(
        locale?.translate(widget.formStep.title) ?? widget.formStep.title,
        style: Theme.of(context).textTheme.headlineSmall,
        textAlign: TextAlign.left,
      ),
    );
  }
  index -= 1;

  if (index == widget.formStep.questions.length) {
    return widget.formStep.optional
        ? Padding(
            padding: const EdgeInsets.all(8.0),
            child: TextButton(
              onPressed: () => skipQuestion(),
              child: Text(locale?.translate("Skip these questions") ??
                  "Skip these questions"),
            ),
          )
        : Container();
  }

  return Padding(
    padding: const EdgeInsets.only(bottom: 8.0),
    child: Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(
            locale?.translate(widget.formStep.questions[index].title) ??
                widget.formStep.questions[index].title,
            style: Theme.of(context).textTheme.titleLarge,
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: stepBody(
            widget.formStep.questions[index].identifier,
            widget.formStep.questions[index].answerFormat,
          ),
        ),
        Divider(
            indent: 1,
            endIndent: 1,
            color: Theme.of(context).dividerColor,
            thickness: 2)
      ],
    ),
  );
}