requestCountrySelector method

  1. @override
Future<Country?> requestCountrySelector(
  1. BuildContext context
)
override

Implementation

@override
Future<Country?> requestCountrySelector(BuildContext context) async {
  OverlayEntry? dropdownOverlayEntry;
  final completer = Completer<Country?>();

  RenderBox renderBox = context.findRenderObject() as RenderBox;
  final size = renderBox.size;

  dropdownOverlayEntry = OverlayEntry(
    builder: (context) {
      return GestureDetector(
        onTap: () {
          dropdownOverlayEntry?.remove();
          completer.complete(null);
        },
        behavior: HitTestBehavior.translucent,
        child: Stack(
          clipBehavior: Clip.hardEdge,
          children: [
            CompositedTransformFollower(
              offset:
                  offsetHeight != null ? Offset(0, size.height).translate(0, offsetHeight!) : Offset(0, size.height),
              link: layerLink,
              showWhenUnlinked: false,
              child: Material(
                borderRadius: borderRadius,
                color: backgroundColor,
                child: SizedBox(
                  height: listHeight,
                  width: size.width,
                  child: _getCountrySelector(
                    isBottomSheet: false,
                    onCountrySelected: (country) {
                      completer.complete(country);
                      dropdownOverlayEntry?.remove();
                    },
                  ),
                ),
              ),
            ),
          ],
        ),
      );
    },
  );
  Overlay.of(context).insert(dropdownOverlayEntry);

  return completer.future;
}