Skip to content

Commit 13446e1

Browse files
authored
improvements(example): fix router navigation issue and add improvements (#1767)
* Change http url and add route navigation observer example * Remove comment * Improve sample * Format * Add padding * Fix analyze issues
1 parent d3801f8 commit 13446e1

File tree

2 files changed

+232
-92
lines changed

2 files changed

+232
-92
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

0 commit comments

Comments
 (0)