Skip to content

Commit a38a2aa

Browse files
committed
import widget instead of ui
1 parent 11baf68 commit a38a2aa

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

flutter/lib/src/event_processor/screenshot_event_processor.dart

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import 'dart:async';
22
import 'dart:math';
33
import 'dart:typed_data';
4-
import 'dart:ui' as ui;
4+
import 'dart:ui';
55

6-
import 'package:flutter/widgets.dart';
76
import 'package:sentry/sentry.dart';
87
import '../screenshot/sentry_screenshot_widget.dart';
98
import '../sentry_flutter_options.dart';
109
import 'package:flutter/rendering.dart';
1110
import '../renderer/renderer.dart';
11+
import 'package:flutter/widgets.dart' as widget;
1212

1313
class ScreenshotEventProcessor implements EventProcessor {
1414
final SentryFlutterOptions _options;
@@ -40,7 +40,8 @@ class ScreenshotEventProcessor implements EventProcessor {
4040
}
4141

4242
if (_options.attachScreenshotWhenResumed &&
43-
WidgetsBinding.instance.lifecycleState != AppLifecycleState.resumed) {
43+
widget.WidgetsBinding.instance.lifecycleState !=
44+
AppLifecycleState.resumed) {
4445
_options.logger(SentryLevel.debug,
4546
'Only attaching screenshots when application state is resumed.');
4647
return event;
@@ -59,10 +60,10 @@ class ScreenshotEventProcessor implements EventProcessor {
5960
sentryScreenshotWidgetGlobalKey.currentContext?.findRenderObject();
6061
if (renderObject is RenderRepaintBoundary) {
6162
// ignore: deprecated_member_use
62-
final pixelRatio = ui.window.devicePixelRatio;
63+
final pixelRatio = window.devicePixelRatio;
6364
var imageResult = _getImage(renderObject, pixelRatio);
64-
ui.Image image;
65-
if (imageResult is Future<ui.Image>) {
65+
Image image;
66+
if (imageResult is Future<Image>) {
6667
image = await imageResult;
6768
} else {
6869
image = imageResult;
@@ -83,14 +84,14 @@ class ScreenshotEventProcessor implements EventProcessor {
8384
var ratio = min(ratioWidth, ratioHeight);
8485
if (ratio > 0.0 && ratio < 1.0) {
8586
imageResult = _getImage(renderObject, ratio * pixelRatio);
86-
if (imageResult is Future<ui.Image>) {
87+
if (imageResult is Future<Image>) {
8788
image = await imageResult;
8889
} else {
8990
image = imageResult;
9091
}
9192
}
9293
}
93-
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
94+
final byteData = await image.toByteData(format: ImageByteFormat.png);
9495

9596
final bytes = byteData?.buffer.asUint8List();
9697
if (bytes?.isNotEmpty == true) {
@@ -112,12 +113,12 @@ class ScreenshotEventProcessor implements EventProcessor {
112113
return null;
113114
}
114115

115-
FutureOr<ui.Image> _getImage(
116+
FutureOr<Image> _getImage(
116117
RenderRepaintBoundary repaintBoundary, double pixelRatio) {
117118
// This one is a hack to use https://api.flutter.dev/flutter/rendering/RenderRepaintBoundary/toImage.html on versions older than 3.7 and https://api.flutter.dev/flutter/rendering/RenderRepaintBoundary/toImageSync.html on versions equal or newer than 3.7
118119
try {
119120
return (repaintBoundary as dynamic).toImageSync(pixelRatio: pixelRatio)
120-
as ui.Image;
121+
as Image;
121122
} on NoSuchMethodError catch (_) {
122123
return repaintBoundary.toImage(pixelRatio: pixelRatio);
123124
}

0 commit comments

Comments
 (0)