File tree Expand file tree Collapse file tree 2 files changed +232
-92
lines changed Expand file tree Collapse file tree 2 files changed +232
-92
lines changed Original file line number Diff line number Diff line change
1
+ import 'package:flutter/material.dart' ;
2
+ import 'package:sentry/sentry.dart' ;
3
+
4
+ /// This screen is only used to demonstrate how route navigation works.
5
+ /// Init will create a child span and pop the screen after 3 seconds.
6
+ /// Afterwards the transaction should be seen on the performance page.
7
+ class AutoCloseScreen extends StatefulWidget {
8
+ const AutoCloseScreen ({super .key});
9
+
10
+ @override
11
+ AutoCloseScreenState createState () => AutoCloseScreenState ();
12
+ }
13
+
14
+ class AutoCloseScreenState extends State <AutoCloseScreen > {
15
+ static const delayInSeconds = 3 ;
16
+
17
+ @override
18
+ void initState () {
19
+ super .initState ();
20
+ _doComplexOperationThenClose ();
21
+ }
22
+
23
+ Future <void > _doComplexOperationThenClose () async {
24
+ final activeSpan = Sentry .getSpan ();
25
+ final childSpan = activeSpan? .startChild ('complex operation' ,
26
+ description: 'running a $delayInSeconds seconds operation' );
27
+ await Future .delayed (const Duration (seconds: delayInSeconds));
28
+ childSpan? .finish ();
29
+ // ignore: use_build_context_synchronously
30
+ Navigator .of (context).pop ();
31
+ }
32
+
33
+ @override
34
+ Widget build (BuildContext context) {
35
+ return Scaffold (
36
+ appBar: AppBar (
37
+ title: const Text ('Delayed Screen' ),
38
+ ),
39
+ body: const Center (
40
+ child: Text (
41
+ 'This screen will automatically close in $delayInSeconds seconds...' ,
42
+ textAlign: TextAlign .center,
43
+ ),
44
+ ),
45
+ );
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments