1
1
import 'dart:async' ;
2
2
import 'dart:math' ;
3
3
import 'dart:typed_data' ;
4
- import 'dart:ui' as ui ;
4
+ import 'dart:ui' ;
5
5
6
- import 'package:flutter/widgets.dart' ;
7
6
import 'package:sentry/sentry.dart' ;
8
7
import '../screenshot/sentry_screenshot_widget.dart' ;
9
8
import '../sentry_flutter_options.dart' ;
10
9
import 'package:flutter/rendering.dart' ;
11
10
import '../renderer/renderer.dart' ;
11
+ import 'package:flutter/widgets.dart' as widget;
12
12
13
13
class ScreenshotEventProcessor implements EventProcessor {
14
14
final SentryFlutterOptions _options;
@@ -40,7 +40,8 @@ class ScreenshotEventProcessor implements EventProcessor {
40
40
}
41
41
42
42
if (_options.attachScreenshotWhenResumed &&
43
- WidgetsBinding .instance.lifecycleState != AppLifecycleState .resumed) {
43
+ widget.WidgetsBinding .instance.lifecycleState !=
44
+ AppLifecycleState .resumed) {
44
45
_options.logger (SentryLevel .debug,
45
46
'Only attaching screenshots when application state is resumed.' );
46
47
return event;
@@ -59,10 +60,10 @@ class ScreenshotEventProcessor implements EventProcessor {
59
60
sentryScreenshotWidgetGlobalKey.currentContext? .findRenderObject ();
60
61
if (renderObject is RenderRepaintBoundary ) {
61
62
// ignore: deprecated_member_use
62
- final pixelRatio = ui. window.devicePixelRatio;
63
+ final pixelRatio = window.devicePixelRatio;
63
64
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 >) {
66
67
image = await imageResult;
67
68
} else {
68
69
image = imageResult;
@@ -83,14 +84,14 @@ class ScreenshotEventProcessor implements EventProcessor {
83
84
var ratio = min (ratioWidth, ratioHeight);
84
85
if (ratio > 0.0 && ratio < 1.0 ) {
85
86
imageResult = _getImage (renderObject, ratio * pixelRatio);
86
- if (imageResult is Future <ui. Image >) {
87
+ if (imageResult is Future <Image >) {
87
88
image = await imageResult;
88
89
} else {
89
90
image = imageResult;
90
91
}
91
92
}
92
93
}
93
- final byteData = await image.toByteData (format: ui. ImageByteFormat .png);
94
+ final byteData = await image.toByteData (format: ImageByteFormat .png);
94
95
95
96
final bytes = byteData? .buffer.asUint8List ();
96
97
if (bytes? .isNotEmpty == true ) {
@@ -112,12 +113,12 @@ class ScreenshotEventProcessor implements EventProcessor {
112
113
return null ;
113
114
}
114
115
115
- FutureOr <ui. Image > _getImage (
116
+ FutureOr <Image > _getImage (
116
117
RenderRepaintBoundary repaintBoundary, double pixelRatio) {
117
118
// 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
118
119
try {
119
120
return (repaintBoundary as dynamic ).toImageSync (pixelRatio: pixelRatio)
120
- as ui. Image ;
121
+ as Image ;
121
122
} on NoSuchMethodError catch (_) {
122
123
return repaintBoundary.toImage (pixelRatio: pixelRatio);
123
124
}
0 commit comments