handleShakeEvent static method

Future<void> handleShakeEvent()

Implementation

static Future<void> handleShakeEvent() async {
  try {
    RenderRepaintBoundary? boundary = _findRepaintBoundary();
    if (boundary == null) {
      throw Exception("No RepaintBoundary found.");
    }
    ui.Image image = await boundary.toImage(pixelRatio: 3.0);
    ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
    Uint8List pngBytes = byteData!.buffer.asUint8List();
    String filePath = await _saveImageToFile(pngBytes);
    String uri = Uri.file(filePath).toString();
    await methodChannel.invokeMethod('handleShakeEvent', {'uri': uri});
  } catch (e) {
    print("Failed to handle shake event: $e");
  }
}