Skip to content

Commit 5cb061f

Browse files
Merge pull request #553 from Instabug/chore/enhance-inline-code-doc
Enhance inline code comments of APM related classes
2 parents 138466d + ea86da1 commit 5cb061f

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

lib/src/utils/screen_loading/instabug_capture_screen_loading.dart

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,37 @@ import 'package:instabug_flutter/src/utils/instabug_montonic_clock.dart';
44
import 'package:instabug_flutter/src/utils/screen_loading/screen_loading_manager.dart';
55
import 'package:instabug_flutter/src/utils/screen_loading/screen_loading_trace.dart';
66

7+
/// A widget that tracks and reports screen loading times to Instabug.
8+
///
9+
/// This widget wraps around a child widget and measures the time taken
10+
/// for the screen to fully render. The recorded loading time is reported
11+
/// using the [ScreenLoadingManager].
12+
///
13+
/// ## Usage
14+
/// ```dart
15+
/// InstabugCaptureScreenLoading(
16+
/// screenName: "HomeScreen",
17+
/// child: HomeScreenWidget(),
18+
/// )
19+
/// ```
720
class InstabugCaptureScreenLoading extends StatefulWidget {
21+
/// A unique identifier for the widget used internally for debugging purposes.
822
static const tag = "InstabugCaptureScreenLoading";
923

24+
/// Creates an instance of [InstabugCaptureScreenLoading].
25+
///
26+
/// Requires [screenName] to identify the screen being tracked and [child]
27+
/// which represents the UI component to be rendered.
1028
const InstabugCaptureScreenLoading({
1129
Key? key,
1230
required this.screenName,
1331
required this.child,
1432
}) : super(key: key);
33+
34+
/// The UI component whose loading time is being measured.
1535
final Widget child;
36+
37+
/// The name of the screen being monitored for loading performance.
1638
final String screenName;
1739

1840
@override
@@ -22,9 +44,16 @@ class InstabugCaptureScreenLoading extends StatefulWidget {
2244

2345
class _InstabugCaptureScreenLoadingState
2446
extends State<InstabugCaptureScreenLoading> {
47+
/// Trace object that records screen loading details.
2548
ScreenLoadingTrace? trace;
49+
50+
/// Timestamp in microseconds when the widget is created.
2651
final startTimeInMicroseconds = IBGDateTime.I.now().microsecondsSinceEpoch;
52+
53+
/// Monotonic timestamp in microseconds for more precise duration tracking.
2754
final startMonotonicTimeInMicroseconds = InstabugMonotonicClock.I.now;
55+
56+
/// Stopwatch to measure screen loading time.
2857
final stopwatch = Stopwatch()..start();
2958

3059
@override
@@ -38,7 +67,7 @@ class _InstabugCaptureScreenLoadingState
3867

3968
ScreenLoadingManager.I.startScreenLoadingTrace(trace!);
4069

41-
// to maintain supported versions prior to Flutter 3.0.0
70+
// Ensures compatibility with Flutter versions before 3.0.0
4271
// ignore: invalid_null_aware_operator
4372
WidgetsBinding.instance?.addPostFrameCallback((_) {
4473
stopwatch.stop();

lib/src/utils/screen_loading/screen_loading_manager.dart

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import 'package:instabug_flutter/src/utils/screen_loading/screen_loading_trace.d
99
import 'package:instabug_flutter/src/utils/screen_loading/ui_trace.dart';
1010
import 'package:meta/meta.dart';
1111

12-
/// @nodoc
12+
/// Manages screen loading traces and UI traces for performance monitoring.
13+
///
14+
/// This class handles the tracking of screen loading times and UI transitions,
15+
/// providing an interface for Instabug APM to capture and report performance metrics.
1316
@internal
1417
class ScreenLoadingManager {
1518
ScreenLoadingManager._();
@@ -21,25 +24,33 @@ class ScreenLoadingManager {
2124

2225
static ScreenLoadingManager _instance = ScreenLoadingManager._();
2326

27+
/// Returns the singleton instance of [ScreenLoadingManager].
2428
static ScreenLoadingManager get instance => _instance;
2529

2630
/// Shorthand for [instance]
2731
static ScreenLoadingManager get I => instance;
32+
33+
/// Logging tag for debugging purposes.
2834
static const tag = "ScreenLoadingManager";
35+
36+
/// Stores the current UI trace.
2937
UiTrace? currentUiTrace;
38+
39+
/// Stores the current screen loading trace.
3040
ScreenLoadingTrace? currentScreenLoadingTrace;
3141

32-
/// @nodoc
42+
/// Stores prematurely ended traces for debugging purposes.
3343
@internal
3444
final List<ScreenLoadingTrace> prematurelyEndedTraces = [];
3545

46+
/// Allows setting a custom instance for testing.
3647
@visibleForTesting
3748
// ignore: use_setters_to_change_properties
3849
static void setInstance(ScreenLoadingManager instance) {
3950
_instance = instance;
4051
}
4152

42-
/// @nodoc
53+
/// Resets the flag indicating a screen loading trace has started.
4354
@internal
4455
void resetDidStartScreenLoading() {
4556
// Allows starting a new screen loading capture trace in the same ui trace (without navigating out and in to the same screen)
@@ -59,9 +70,8 @@ class ScreenLoadingManager {
5970
);
6071
}
6172

62-
/// @nodoc
73+
/// Checks if the Instabug SDK is built before calling API methods.
6374
Future<bool> _checkInstabugSDKBuilt(String apiName) async {
64-
// Check if Instabug SDK is Built
6575
final isInstabugSDKBuilt = await Instabug.isBuilt();
6676
if (!isInstabugSDKBuilt) {
6777
InstabugLogger.I.e(
@@ -73,7 +83,7 @@ class ScreenLoadingManager {
7383
return isInstabugSDKBuilt;
7484
}
7585

76-
/// @nodoc
86+
/// Resets the flag indicating a screen loading trace has been reported.
7787
@internal
7888
void resetDidReportScreenLoading() {
7989
// Allows reporting a new screen loading capture trace in the same ui trace even if one was reported before by resetting the flag which is used for checking.
@@ -84,7 +94,7 @@ class ScreenLoadingManager {
8494
);
8595
}
8696

87-
/// @nodoc
97+
/// Starts a new UI trace with a given screen name.
8898
@internal
8999
void resetDidExtendScreenLoading() {
90100
// Allows reporting a new screen loading capture trace in the same ui trace even if one was reported before by resetting the flag which is used for checking.
@@ -176,7 +186,7 @@ class ScreenLoadingManager {
176186
}
177187
}
178188

179-
/// @nodoc
189+
/// Starts a screen loading trace.
180190
@internal
181191
Future<void> startScreenLoadingTrace(ScreenLoadingTrace trace) async {
182192
try {
@@ -225,7 +235,7 @@ class ScreenLoadingManager {
225235
}
226236
}
227237

228-
/// @nodoc
238+
/// Reports the input [ScreenLoadingTrace] to the native side.
229239
@internal
230240
Future<void> reportScreenLoading(ScreenLoadingTrace? trace) async {
231241
try {

0 commit comments

Comments
 (0)