Last active
June 18, 2024 14:32
-
-
Save tolo/922fd838cdea30b17121533b0012eda4 to your computer and use it in GitHub Desktop.
Revisions
-
tolo revised this gist
Jun 18, 2024 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,10 +61,14 @@ void main() { GlobalKey<_StatefulTestState>(debugLabel: 'testState'); final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'root'); final GlobalKey<NavigatorState> shellNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'shell'); final ValueNotifier<RoutingConfig> config = ValueNotifier<RoutingConfig>( RoutingConfig( routes: <RouteBase>[ ShellRoute( navigatorKey: shellNavigatorKey, routes: <RouteBase>[ GoRoute(path: '/', builder: (_, __) => const Text('home')), ], @@ -74,7 +78,7 @@ void main() { ), ); addTearDown(config.dispose); await createRouterWithRoutingConfig( navigatorKey: rootNavigatorKey, config, tester, @@ -86,6 +90,7 @@ void main() { config.value = RoutingConfig( routes: <RouteBase>[ ShellRoute( navigatorKey: shellNavigatorKey, routes: <RouteBase>[ GoRoute(path: '/', builder: (_, __) => const Text('home')), GoRoute(path: '/abc', builder: (_, __) => const Text('/abc')), -
tolo created this gist
Jun 18, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,126 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; import 'test_helpers.dart'; void main() { // ... /// THIS WORKS testWidgets('routing config works after routing changes case 3', (WidgetTester tester) async { final GlobalKey<_StatefulTestState> key = GlobalKey<_StatefulTestState>(debugLabel: 'testState'); final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'root'); final ValueNotifier<RoutingConfig> config = ValueNotifier<RoutingConfig>( RoutingConfig( routes: <RouteBase>[ GoRoute( path: '/', builder: (_, __) => StatefulTest(key: key, child: const Text('home'))), ], ), ); addTearDown(config.dispose); await createRouterWithRoutingConfig( navigatorKey: rootNavigatorKey, config, tester, errorBuilder: (_, __) => const Text('error'), ); expect(find.text('home'), findsOneWidget); key.currentState!.value = 1; config.value = RoutingConfig( routes: <RouteBase>[ GoRoute( path: '/', builder: (_, __) => StatefulTest(key: key, child: const Text('home'))), GoRoute(path: '/abc', builder: (_, __) => const Text('/abc')), ], ); await tester.pumpAndSettle(); expect(key.currentState!.value == 1, isTrue); }); /// THIS CRASHES (duplicate GlobalKey) testWidgets('routing config works with shell route', (WidgetTester tester) async { final GlobalKey<_StatefulTestState> key = GlobalKey<_StatefulTestState>(debugLabel: 'testState'); final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'root'); final ValueNotifier<RoutingConfig> config = ValueNotifier<RoutingConfig>( RoutingConfig( routes: <RouteBase>[ ShellRoute( routes: <RouteBase>[ GoRoute(path: '/', builder: (_, __) => const Text('home')), ], builder: (_, __, Widget widget) => StatefulTest(key: key, child: widget)), ], ), ); addTearDown(config.dispose); await createRouterWithRoutingConfig( navigatorKey: rootNavigatorKey, config, tester, errorBuilder: (_, __) => const Text('error'), ); expect(find.text('home'), findsOneWidget); key.currentState!.value = 1; config.value = RoutingConfig( routes: <RouteBase>[ ShellRoute( routes: <RouteBase>[ GoRoute(path: '/', builder: (_, __) => const Text('home')), GoRoute(path: '/abc', builder: (_, __) => const Text('/abc')), ], builder: (_, __, Widget widget) => StatefulTest(key: key, child: widget)), ], ); await tester.pumpAndSettle(); expect(key.currentState!.value == 1, isTrue); }); // ... } class StatefulTest extends StatefulWidget { const StatefulTest({super.key, required this.child}); final Widget child; @override State<StatefulWidget> createState() => _StatefulTestState(); } class _StatefulTestState extends State<StatefulTest> { int value = 0; @override Widget build(BuildContext context) { return Column( children: <Widget>[ widget.child, Text('State: $value'), ], ); } }