onTextFieldFocus method

void onTextFieldFocus({
  1. Color? circularIndicatorColor,
})

Implementation

void onTextFieldFocus({Color? circularIndicatorColor}) {
  setState(() {
    isSearchBoxSelected = true;
  });
  final RenderBox searchBoxRenderBox =
      // ignore: avoid_as
      context.findRenderObject() as RenderBox;
  final RenderBox overlay =
      // ignore: avoid_as
      Overlay.of(context).context.findRenderObject() as RenderBox;
  final width = searchBoxRenderBox.size.width;
  final position = RelativeRect.fromRect(
    Rect.fromPoints(
      searchBoxRenderBox.localToGlobal(
        searchBoxRenderBox.size.topLeft(Offset.zero),
        ancestor: overlay,
      ),
      searchBoxRenderBox.localToGlobal(
        searchBoxRenderBox.size.topRight(Offset.zero),
        ancestor: overlay,
      ),
    ),
    Offset.zero & overlay.size,
  );
  overlaySearchList = OverlayEntry(
      builder: (context) => Positioned(
            left: position.left,
            width: width,
            child: CompositedTransformFollower(
              offset: const Offset(
                0,
                56,
              ),
              showWhenUnlinked: false,
              link: _layerLink,
              child: Card(
                margin: const EdgeInsets.all(12),
                color: Colors.white,
                elevation: 5,
                shape: const RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(4)),
                ),
                child: _searchList.isNotEmpty
                    ? Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: <Widget>[
                          Padding(
                            padding: const EdgeInsets.all(8),
                            child: InkWell(
                              child: const Icon(
                                Icons.close,
                                size: 22,
                              ),
                              onTap: onCloseOverlaySearchList,
                            ),
                          ),
                          Container(
                            height: overlaySearchListHeight,
                            child: Scrollbar(
                              child: ListView.separated(
                                padding:
                                    const EdgeInsets.symmetric(vertical: 4),
                                separatorBuilder: (context, index) =>
                                    const Divider(
                                  height: 1,
                                ),
                                itemBuilder: (context, index) => Material(
                                  color: Colors.transparent,
                                  child: InkWell(
                                    onTap: () => onSearchListItemSelected(
                                        _searchList[index]),
                                    child:
                                        widget.overlaySearchListItemBuilder(
                                      _searchList.elementAt(index),
                                    ),
                                  ),
                                ),
                                itemCount: _searchList.length,
                              ),
                            ),
                          ),
                        ],
                      )
                    : isLoading ?? false
                        ? Center(
                            child: Padding(
                              padding:
                                  const EdgeInsets.symmetric(vertical: 10),
                              child: CircularProgressIndicator(
                                color: circularIndicatorColor ?? Colors.blue,
                              ),
                            ),
                          )
                        : widget.noItemsFoundWidget != null
                            ? Center(
                                child: widget.noItemsFoundWidget,
                              )
                            : Container(
                                margin: const EdgeInsets.all(8),
                                child: const Text(
                                  'No items found',
                                  style: TextStyle(fontSize: 18),
                                ),
                              ),
              ),
            ),
          ));
  Overlay.of(context).insert(overlaySearchList!);
}