handle method

  1. @override
Future handle(
  1. MethodCall call
)
override

Implementation

@override
Future<dynamic> handle(MethodCall call) async {
  try {
    NLogger.i('Handling app component data, arguments: ${call.arguments}');
    final args = call.arguments;
    final newHeight = args['height'].toDouble();
    final newWidth = args['width'].toDouble();
    final tag = args['tag'];

    NLogger.i('New height: $newHeight, New width: $newWidth');

    if (newHeight == 0.0 || newWidth == 0.0) {
      return {'success': false};
    }

    final viewState = NudgeAppComponentViewState(
      viewId: tag,
      height: newHeight,
      width: newWidth,
      isViewReady: newHeight == 800.0 ? false : true,
    );

    // Notify listeners (e.g., the widget) about the new view state
    NudgeCoreV2NativeServices().addACViewDataToStream(viewState);

    return {'success': true};
  } catch (e) {
    final viewState = NudgeAppComponentViewState(
      height: 800.0,
      width: double.infinity,
      isViewReady: false,
      errorMessage: 'Error: $e',
    );

    NudgeCoreV2NativeServices().addACViewDataToStream(viewState);

    return {'error': e.toString()};
  }
}