updateView method

void updateView(
  1. GlobalKey<State<StatefulWidget>>? key,
  2. String method
)

Implementation

void updateView(GlobalKey? key, String method) {
  if (key == null || _methodChannel == null) return;

  final state = key.currentState as EBNativeAdBaseState?;
  if (state == null) return;

  Rect rect = _getViewFrame(state.rectKey);

  Map<String, dynamic> params;

  if (defaultTargetPlatform == TargetPlatform.android) {
    double devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
    params = {
      'x': (rect.left * devicePixelRatio).round(),
      'y': (rect.top * devicePixelRatio).round(),
      'width': (rect.width * devicePixelRatio).round(),
      'height': (rect.height * devicePixelRatio).round(),
    };
  } else if (defaultTargetPlatform == TargetPlatform.iOS) {
    params = {
      'x': rect.left,
      'y': rect.top,
      'width': rect.width,
      'height': rect.height,
    };
  } else {
    return;
  }

  EBBaseStyle? baseStyle = state.widget.baseStyle;

  if (baseStyle != null) {
    params["styles"] = baseStyle.toMap();
  }

  _methodChannel?.invokeMethod(method, params);
}