buildPopover method

Widget buildPopover(
  1. BuildContext context
)

Implementation

Widget buildPopover(BuildContext context) {
  final theme = Theme.of(context);
  return TextFieldTapRegion(
    child: Data.inherit(
      data: this,
      child: ConstrainedBox(
        constraints: widget.popoverConstraints,
        child: OutlinedContainer(
          child: AnimatedBuilder(
            animation: Listenable.merge([_suggestions, _selectedSuggestions]),
            builder: (context, child) {
              return ListView(
                shrinkWrap: true,
                padding: EdgeInsets.all(theme.scaling * 4),
                children: [
                  for (int i = 0; i < _suggestions.value.length; i++)
                    SelectedButton(
                      style: const ButtonStyle.ghost(),
                      selectedStyle: const ButtonStyle.secondary(),
                      value: i == _selectedSuggestions.value,
                      onChanged: (value) {
                        if (value) {
                          widget.onSuggestionChoosen?.call(i);
                          _controller.clear();
                          _selectedSuggestions.value = -1;
                          _popoverController.close();
                        }
                      },
                      child: Row(
                        children: [
                          if (widget.suggestionLeadingBuilder != null) ...[
                            widget.suggestionLeadingBuilder!(
                                context, _suggestions.value[i]),
                            SizedBox(
                                width:
                                    theme.scaling * 10), // Add spacing here
                          ],
                          Expanded(
                            child: widget.suggestionBuilder
                                    ?.call(context, _suggestions.value[i]) ??
                                Text(_suggestions.value[i].toString())
                                    .normal()
                                    .small(),
                          ),
                          if (widget.suggestionTrailingBuilder != null) ...[
                            SizedBox(
                                width:
                                    theme.scaling * 10), // Add spacing here
                            widget.suggestionTrailingBuilder!
                                    (context, _suggestions.value[i])
                                .normal()
                                .small(),
                          ],
                        ],
                      ),
                    ),
                ],
              );
            },
          ),
        ),
      ),
    ),
  );
}