Я портирую мобильное приложение на Интернет, это приложение использует виджет CustomPaint
для рисования на основе пользовательских данных. С RepaintBoundary
я делаю снимок экрана с краской и сохраняю его на устройстве, используя пакет save_in_gallery.dart
.
В веб-приложении чертежная часть работает нормально, но я не могу получить часть снимка экрана или часть сохранения изображения на работу. Вот код, который я использую для сохранения
RenderRepaintBoundary boundary =
globalKey.currentContext.findRenderObject();
ui.Image image = await boundary.toImage();
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
final res = await _imageSaver.saveImage(
imageBytes: pngBytes,
directoryName: "dir_name",
);
print(res);
print(pngBytes);
}
Вот ошибка на консоли chrome, когда я нажимаю кнопку, которая активирует RepaintBoundary
(снимок экрана), и функцию сохранения:
errors.dart:146 Uncaught (in promise) Error: Exception: Incorrect sequence of push/pop operations while building scene surfaces. After building the scene the persisted surface stack must contain a single element which corresponds to the scene itself (_PersistedScene). All other surfaces should have been popped off the stack. Found the following surfaces in the stack:
PersistedScene, PersistedTransform
at Object.throw_ [as throw] (errors.dart:195)
at scene_builder.dart:27
at _engine.SurfaceSceneBuilder.new.get [_persistedScene] (scene_builder.dart:34)
at _engine.SurfaceSceneBuilder.new.build (scene_builder.dart:544)
at layer$.OffsetLayer.new.buildScene (layer.dart:808)
at layer$.OffsetLayer.new.toImage (layer.dart:1241)
at toImage.next (<anonymous>)
at runBody (async_patch.dart:86)
at Object._async [as async] (async_patch.dart:125)
at layer$.OffsetLayer.new.toImage (layer.dart:1230)
at proxy_box.RenderRepaintBoundary.new.toImage (proxy_box.dart:2963)
at DrawCustomPainter._DrawCustomPainterState.new._capturePng (DrawCustomPainter.dart:37)
at _capturePng.next (<anonymous>)
at runBody (async_patch.dart:86)
at Object._async [as async] (async_patch.dart:125)
at DrawCustomPainter._DrawCustomPainterState.new.[_capturePng] (DrawCustomPainter.dart:34)
at _InkResponseState.new.[_handleTap] (ink_well.dart:779)
at ink_well.dart:862
at tap.TapGestureRecognizer.new.invokeCallback (recognizer.dart:182)
at tap.TapGestureRecognizer.new.handleTapUp (tap.dart:504)
at tap.TapGestureRecognizer.new.[_checkUp] (tap.dart:282)
at tap.TapGestureRecognizer.new.acceptGesture (tap.dart:254)
at arena.GestureArenaManager.new.sweep (arena.dart:156)
at binding$5.WidgetsFlutterBinding.new.handleEvent (binding.dart:222)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent (binding.dart:198)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerEvent] (binding.dart:156)
at binding$5.WidgetsFlutterBinding.new.[_flushPointerEventQueue] (binding.dart:102)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerDataPacket] (binding.dart:86)
at Object._invoke1 (window.dart:590)
at _engine.EngineWindow.new.invokeOnPointerDataPacket (window.dart:238)
at _engine.PointerBinding.__.[_onPointerData] (pointer_binding.dart:129)
at pointer_binding.dart:457
at pointer_binding.dart:418
at HTMLElement.<anonymous> (pointer_binding.dart:195)