This repository was archived by the owner on Dec 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathinstabug_navigator_observer.dart
More file actions
75 lines (66 loc) · 2.65 KB
/
instabug_navigator_observer.dart
File metadata and controls
75 lines (66 loc) · 2.65 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import 'package:flutter/material.dart';
import 'package:instabug_flutter/instabug_flutter.dart';
import 'package:instabug_flutter/src/models/instabug_route.dart';
import 'package:instabug_flutter/src/modules/instabug.dart';
import 'package:instabug_flutter/src/utils/instabug_logger.dart';
import 'package:instabug_flutter/src/utils/repro_steps_constants.dart';
import 'package:instabug_flutter/src/utils/screen_loading/screen_loading_manager.dart';
import 'package:instabug_flutter/src/utils/screen_name_masker.dart';
class InstabugNavigatorObserver extends NavigatorObserver {
final List<InstabugRoute> _steps = [];
void screenChanged(Route newRoute) {
try {
final rawScreenName = newRoute.settings.name.toString().trim();
final screenName = rawScreenName.isEmpty
? ReproStepsConstants.emptyScreenFallback
: rawScreenName;
final maskedScreenName = ScreenNameMasker.I.mask(screenName);
final route = InstabugRoute(
route: newRoute,
name: maskedScreenName,
);
//ignore: invalid_null_aware_operator
WidgetsBinding.instance?.addPostFrameCallback((_) async {
// Starts a the new UI trace which is exclusive to screen loading
ScreenLoadingManager.I.startUiTrace(maskedScreenName, screenName);
// If there is a step that hasn't been pushed yet
if (_steps.isNotEmpty) {
await reportScreenChange(_steps.last.name);
}
// Check again if there is a step that hasn't been pushed yet after the async operation above.
if (_steps.isNotEmpty) {
// Report the last step and remove it from the list
_steps.removeLast();
}
// Add the new step to the list
_steps.add(route);
// If this route is in the array, report it
if (_steps.contains(route)) {
await reportScreenChange(route.name);
}
// Check again if this route is still in the list after async operation, remove it from the list
if (_steps.contains(route)) {
_steps.remove(route);
}
});
} catch (e) {
InstabugLogger.I.e('Reporting screen change failed:', tag: Instabug.tag);
InstabugLogger.I.e(e.toString(), tag: Instabug.tag);
}
}
Future<void> reportScreenChange(String name) async {
// Wait for the animation to complete
await Future.delayed(const Duration(milliseconds: 100));
Instabug.reportScreenChange(name);
}
@override
void didPop(Route route, Route? previousRoute) {
if (previousRoute != null) {
screenChanged(previousRoute);
}
}
@override
void didPush(Route route, Route? previousRoute) {
screenChanged(route);
}
}