refreshInputRegion static method

void refreshInputRegion()

This will be called whenever there is a change in the InputRegion widget. like size change, position change, etc.

This will change the native window input region to the new input region.

Implementation

static void refreshInputRegion() {
  /// Sort the keys based on the depth of the widget.
  final List<({GlobalKey key, bool isNegative})> keys = [
    ..._positiveRegionKeys.map((key) => (key: key, isNegative: false)),
    ..._negativeRegionKeys.map((key) => (key: key, isNegative: true)),
  ];
  keys.sort((a, b) => _findDepth(a.key).compareTo(_findDepth(b.key)));

  for (final item in keys) {
    /// Get the size and position of the widget.
    final RenderBox renderBox =
        item.key.currentContext!.findRenderObject() as RenderBox;
    final size = renderBox.size;
    final position = renderBox.localToGlobal(Offset.zero);

    /// Set the input region to the size and position of the widget.
    final Rect region = Rect.fromLTWH(
      position.dx,
      position.dy,
      size.width,
      size.height,
    );

    if (item.isNegative) {
      FlLinuxWindowManager.instance.subtractInputRegion(inputRegion: region);
    } else {
      FlLinuxWindowManager.instance.addInputRegion(inputRegion: region);
    }
  }
}