Skip to content

Commit 98bc647

Browse files
committed
adapt example app to handle multiple navigatorKeys
1 parent eea494e commit 98bc647

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

flutter/example/lib/main.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ const String exampleUrl = 'https://jsonplaceholder.typicode.com/todos/';
4141
const _channel = MethodChannel('example.flutter.sentry.io');
4242
var _isIntegrationTest = false;
4343

44-
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
44+
final GlobalKey<NavigatorState> navigatorKey1 = GlobalKey<NavigatorState>();
45+
final GlobalKey<NavigatorState> navigatorKey2 = GlobalKey<NavigatorState>();
46+
47+
final navigatorKeys = [navigatorKey1, navigatorKey2];
4548

4649
Future<void> main() async {
4750
await setupSentry(
@@ -91,7 +94,7 @@ Future<void> setupSentry(
9194

9295
options.maxRequestBodySize = MaxRequestBodySize.always;
9396
options.maxResponseBodySize = MaxResponseBodySize.always;
94-
options.navigatorKey = navigatorKey;
97+
options.navigatorKeys = navigatorKeys;
9598

9699
_isIntegrationTest = isIntegrationTest;
97100
if (_isIntegrationTest) {
@@ -120,7 +123,7 @@ class _MyAppState extends State<MyApp> {
120123
create: (_) => ThemeProvider(),
121124
child: Builder(
122125
builder: (context) => MaterialApp(
123-
navigatorKey: navigatorKey,
126+
navigatorKey: navigatorKeys[View.of(context).viewId - 1],
124127
navigatorObservers: [
125128
SentryNavigatorObserver(),
126129
],

0 commit comments

Comments
 (0)