Widget _inputBuilder()

in frontend/frontend-flutter/lib/utils/custom_input_field.dart [131:279]


  Widget _inputBuilder() {
    final query = MediaQuery.of(context);
    final buttonPadding = InheritedChatTheme.of(context)
        .theme
        .inputPadding
        .copyWith(left: 16, right: 16);
    final safeAreaInsets = isMobile
        ? EdgeInsets.fromLTRB(
            query.padding.left,
            0,
            query.padding.right,
            query.viewInsets.bottom + query.padding.bottom,
          )
        : EdgeInsets.zero;
    final textPadding = InheritedChatTheme.of(context)
        .theme
        .inputPadding
        .copyWith(left: 0, right: 0)
        .add(
          EdgeInsets.fromLTRB(
            widget.onAttachmentPressed != null ? 0 : 24,
            0,
            _sendButtonVisible ? 0 : 24,
            0,
          ),
        );

    return Focus(
      autofocus: !widget.options.autofocus,
      child: Padding(
        padding: InheritedChatTheme.of(context).theme.inputMargin,
        child: Material(
          borderRadius: InheritedChatTheme.of(context).theme.inputBorderRadius,
          color: InheritedChatTheme.of(context).theme.inputBackgroundColor,
          surfaceTintColor:
              InheritedChatTheme.of(context).theme.inputSurfaceTintColor,
          elevation: InheritedChatTheme.of(context).theme.inputElevation,
          child: Container(
            decoration: BoxDecoration(
              color: Color(0xFFF0F2F6), // Background color
            ),
            //InheritedChatTheme.of(context).theme.inputContainerDecoration,
            padding: safeAreaInsets,
            child: Row(
              textDirection: TextDirection.ltr,
              children: [
                /*if (widget.onAttachmentPressed != null)
                  AttachmentButton(
                    isLoading: widget.isAttachmentUploading ?? false,
                    onPressed: widget.onAttachmentPressed,
                    padding: buttonPadding,
                  ),*/
                Container(width: 30),
                Expanded(
                  child: Padding(
                      padding: textPadding,
                      child: FutureBuilder(
                        future: getAllquestions(),
                        builder: (context, snapshot) {
                          if(snapshot.hasData) {
                            suggestionsList = snapshot.data!;
                            print(
                                "CustomInputField: build() : _inputBuilder() : suggestionList.length = ${suggestionsList.length}");
                          }
                          return TypeAheadField<Suggestion>(
                            hideOnEmpty: true,
                            controller: _textController,
                            direction: VerticalDirection.up,
                            loadingBuilder: (context) =>
                                const Text('Loading...'),
                            onSelected: (entry) {

                              _textController.text = entry.suggestion!;
                              entry.scenarioNumber;
                              BlocProvider.of<NewSuggestionCubit>(context)
                                  .generateNewSuggestions(
                                      entry.scenarioNumber!, entry.suggestion!,
                                      isACannedQuestion: false,
                                userGrouping: entry.userGrouping
                              );
                            },
                            itemBuilder: (context, entry) {
                              print(
                                  "CustomInputField: build() : TypeAheadField : _inputBuilder():  itemBuilder: entry = $entry");
                              return ListTile(
                                title: Text(entry.suggestion!),
                              );
                            },
                            suggestionsCallback:
                                _textController.text.length <= 1
                                    ? suggestionsEmptyCallback
                                    : suggestionsCallback,
                            builder:
                                (context, _textController, inputFocusNode) {
                              print(
                                  "CustomInputField: build() : TypeAheadField : _inputBuilder():  builder: focusNode = $inputFocusNode");
                              return TextField(
                                enabled: widget.options.enabled,
                                autocorrect: widget.options.autocorrect,
                                autofocus: widget.options.autofocus,
                                enableSuggestions:
                                    widget.options.enableSuggestions,
                                controller: _textController,
                                cursorColor: InheritedChatTheme.of(context)
                                    .theme
                                    .inputTextCursorColor,
                                decoration: InputDecoration(
                                  border: OutlineInputBorder(
                                    borderRadius: BorderRadius.circular(
                                        50.0), // Adjust the radius as needed
                                  ),
                                  //labelText: 'Password',
                                  filled: true,
                                  fillColor: Colors.white,
                                  suffixIcon: Visibility(
                                    visible: _sendButtonVisible,
                                    child: IconButton(
                                      onPressed: () {
                                        print(
                                            "CustomInputField: build() : _inputBuilder() : TypeAheadField : IconButton : onPressed: ()");
                                        _handleSendPressed();
                                      },
                                      icon: Icon(Icons.send),
                                    ),
                                  ),
                                ),
                                focusNode: inputFocusNode,
                                keyboardType: widget.options.keyboardType,
                                maxLines: 5,
                                minLines: 1,
                                onChanged: widget.options.onTextChanged,
                                onTap: widget.options.onTextFieldTap,
                                style: TextStyle(color: Colors.black),
                                textCapitalization:
                                    TextCapitalization.sentences,
                              );
                            },
                          );
                        },
                      )),
                ),
                Container(width: 30),
              ],
            ),
          ),
        ),
      ),
    );
  }