-
-
Notifications
You must be signed in to change notification settings - Fork 223
/
sentry_display_widget.dart
60 lines (53 loc) · 2.09 KB
/
sentry_display_widget.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'package:flutter/cupertino.dart';
import 'time_to_initial_display_tracker.dart';
import '../frame_callback_handler.dart';
/// A widget that reports the Time To Initially Displayed (TTID) of its child widget.
///
/// This widget wraps around another widget to measure and report the time it takes
/// for the child widget to be initially displayed on the screen. This method
/// allows a more accurate measurement than what the default TTID implementation
/// provides. The TTID measurement begins when the route to the widget is pushed and ends
/// when `addPostFramecallback` is triggered.
///
/// Wrap the widget you want to measure with [SentryDisplayWidget], and ensure that you
/// have set up Sentry's routing instrumentation according to the Sentry documentation.
///
/// ```dart
/// SentryDisplayWidget(
/// child: MyWidget(),
/// )
/// ```
///
/// Make sure to configure Sentry's routing instrumentation in your app by following
/// the guidelines provided in Sentry's documentation for Flutter integrations:
/// https://docs.sentry.io/platforms/flutter/integrations/routing-instrumentation/
///
/// See also:
/// - [Sentry's documentation on Flutter integrations](https://docs.sentry.io/platforms/flutter/)
/// for more information on how to integrate Sentry into your Flutter application.
class SentryDisplayWidget extends StatefulWidget {
final Widget child;
final FrameCallbackHandler _frameCallbackHandler;
SentryDisplayWidget({
super.key,
required this.child,
@visibleForTesting FrameCallbackHandler? frameCallbackHandler,
}) : _frameCallbackHandler =
frameCallbackHandler ?? DefaultFrameCallbackHandler();
@override
_SentryDisplayWidgetState createState() => _SentryDisplayWidgetState();
}
class _SentryDisplayWidgetState extends State<SentryDisplayWidget> {
@override
void initState() {
super.initState();
TimeToInitialDisplayTracker().markAsManual();
widget._frameCallbackHandler.addPostFrameCallback((_) {
TimeToInitialDisplayTracker().completeTracking();
});
}
@override
Widget build(BuildContext context) {
return widget.child;
}
}