afterFirstLayout method

  1. @override
void afterFirstLayout(
  1. BuildContext context
)
override

Implementation

@override
void afterFirstLayout(BuildContext context) {
  final inputCtx = context;
  _controller!.initialize(context, OverlayEntry(
    builder: (context) {
      return StreamBuilder<ChipSuggestions<T>?>(
        stream: _controller!.suggestionsStream.flatten(),
        builder: (BuildContext context,
            AsyncSnapshot<ChipSuggestions<T>?> snapshot) {
          final RenderBox box = inputCtx.findRenderObject() as RenderBox;
          size = box.size;
          if (snapshot.data?.suggestions?.isNotEmpty == true) {
            final _suggestions = snapshot.data!.suggestions;
            return Positioned(
              width: size.width,
              child: CompositedTransformFollower(
                link: _layerLink,
                showWhenUnlinked: false,
                offset: Offset(0.0, size.height + 5.0),
                child: Material(
                  elevation: widget.elevation ?? 2.0,
                  child: ListView.builder(
                    shrinkWrap: true,
                    padding: EdgeInsets.zero,
                    itemCount: snapshot.data?.suggestions?.length ?? 0,
                    itemBuilder: (BuildContext context, int index) {
                      return widget.suggestionBuilder!(
                        context,
                        _controller,
                        index,
                        _suggestions![index],
                      );
                    },
                  ),
                ),
              ),
            );
          } else {
            return Container();
          }
        },
      );
    },
  ));

  if (_controller!.enabled && widget.autofocus == true) {
    requestKeyboard(context);
  }
}