Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions flutter/example/lib/auto_close_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import 'package:sentry/sentry.dart';

/// This screen is only used to demonstrate how route navigation works.
/// Init will create a child span and pop the screen after 3 seconds.
/// Afterwards the transaction should be seen on the performance page.
class AutoCloseScreen extends StatefulWidget {
const AutoCloseScreen({super.key});

@override
AutoCloseScreenState createState() => AutoCloseScreenState();
}

class AutoCloseScreenState extends State<AutoCloseScreen> {
static const delayInSeconds = 3;

@override
void initState() {
super.initState();
_doComplexOperationThenClose();
}

Future<void> _doComplexOperationThenClose() async {
final activeSpan = Sentry.getSpan();
final childSpan = activeSpan?.startChild('complex operation',
description: 'running a $delayInSeconds seconds operation');
await Future.delayed(const Duration(seconds: delayInSeconds));
childSpan?.finish();
// ignore: use_build_context_synchronously
Navigator.of(context).pop();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Delayed Screen'),
),
body: const Center(
child: Text(
'This screen will automatically close in $delayInSeconds seconds...',
textAlign: TextAlign.center,
),
),
);
}
}
Loading