From 80e5cf1bf564f487eb73fb12fd732cff959faeef Mon Sep 17 00:00:00 2001 From: GeekAbdelouahed Date: Sun, 10 Sep 2023 01:17:00 +0100 Subject: [PATCH 1/8] feat: add initialLocation to StatefulShellBranchConfig --- packages/go_router_builder/lib/src/route_config.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index 5925c11541f..d2ff611961e 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -137,6 +137,7 @@ class StatefulShellBranchConfig extends RouteBaseConfig { required super.routeDataClass, required super.parent, this.restorationScopeId, + this.initialLocation, }) : super._(); /// The command for calling the navigator key getter from the ShellRouteData. @@ -145,6 +146,9 @@ class StatefulShellBranchConfig extends RouteBaseConfig { /// The restoration scope id. final String? restorationScopeId; + /// The initial route. + final String? initialLocation; + @override Iterable classDeclarations() => []; @@ -153,7 +157,8 @@ class StatefulShellBranchConfig extends RouteBaseConfig { @override String get routeConstructorParameters => '${navigatorKey == null ? '' : 'navigatorKey: $navigatorKey,'}' - '${restorationScopeId == null ? '' : 'restorationScopeId: $restorationScopeId,'}'; + '${restorationScopeId == null ? '' : 'restorationScopeId: $restorationScopeId,'}' + '${initialLocation == null ? '' : 'initialLocation: $initialLocation,'}'; @override String get routeDataClassName => 'StatefulShellBranchData'; @@ -502,6 +507,10 @@ abstract class RouteBaseConfig { classElement, parameterName: r'$restorationScopeId', ), + initialLocation: _generateParameterGetterCode( + classElement, + parameterName: r'$initialLocation', + ), ); break; case 'TypedGoRoute': From c8079d3bf695a68b17fe3040cbe5c968e43dc63e Mon Sep 17 00:00:00 2001 From: GeekAbdelouahed Date: Sun, 10 Sep 2023 09:18:45 +0100 Subject: [PATCH 2/8] chore: update CHANGELOG.md and pubspec.yaml --- packages/go_router_builder/CHANGELOG.md | 3 +++ packages/go_router_builder/pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 6c49de0a2ab..dd9384f0408 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.3.2 +* Add initialLocation with StatefulShellBranchConfig + ## 2.3.1 * Adds pub topics to package metadata. diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 0b6f4d4247a..838149af9e9 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -2,7 +2,7 @@ name: go_router_builder description: >- A builder that supports generated strongly-typed route helpers for package:go_router -version: 2.3.1 +version: 2.3.2 repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22 From 2749af091acd570dbec0432598c987698f7e19b0 Mon Sep 17 00:00:00 2001 From: GeekAbdelouahed Date: Mon, 18 Sep 2023 19:57:59 +0100 Subject: [PATCH 3/8] feat: add unit test --- .../test_inputs/statefull_shell_branch_data.dart | 12 ++++++++++++ .../statefull_shell_branch_data.dart.expect | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart create mode 100644 packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect diff --git a/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart b/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart new file mode 100644 index 00000000000..ec9b7bbc824 --- /dev/null +++ b/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart @@ -0,0 +1,12 @@ +// 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:go_router/go_router.dart'; + +@TypedStatefulShellBranch() +class ShellRouteBranchData extends StatefulShellBranchData { + const ShellRouteBranchData(); + + static const String $initialLocation = '/main/second-tab'; +} diff --git a/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect b/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect new file mode 100644 index 00000000000..a1c77bf4c55 --- /dev/null +++ b/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect @@ -0,0 +1,3 @@ +RouteBase get $shellRouteBranchData => StatefulShellBranchData.$branch( + initialLocation: ShellRouteBranchData.$initialLocation, + ); \ No newline at end of file From 873ce6679431967f14fb0827a78a5f224aa1d80f Mon Sep 17 00:00:00 2001 From: GeekAbdelouahed Date: Mon, 18 Sep 2023 20:34:29 +0100 Subject: [PATCH 4/8] feat: add stateful shell route initial location example --- ..._shell_route_initial_location_example.dart | 264 ++++++++++++++++++ ...hell_route_initial_location_example.g.dart | 116 ++++++++ 2 files changed, 380 insertions(+) create mode 100644 packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart create mode 100644 packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart diff --git a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart new file mode 100644 index 00000000000..79e9942964f --- /dev/null +++ b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart @@ -0,0 +1,264 @@ +// 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/material.dart'; +import 'package:go_router/go_router.dart'; + +part 'stateful_shell_route_initial_location_example.g.dart'; + +void main() => runApp(App()); + +class App extends StatelessWidget { + App({super.key}); + + @override + Widget build(BuildContext context) => MaterialApp.router( + routerConfig: _router, + ); + + final GoRouter _router = GoRouter( + routes: $appRoutes, + initialLocation: '/first', + ); +} + +class HomeScreen extends StatelessWidget { + const HomeScreen({super.key}); + + @override + Widget build(BuildContext context) => Scaffold( + appBar: AppBar(title: const Text('foo')), + ); +} + +@TypedStatefulShellRoute( + branches: >[ + TypedStatefulShellBranch( + routes: >[ + TypedGoRoute(path: '/first'), + ], + ), + TypedStatefulShellBranch( + routes: >[ + TypedGoRoute(path: '/second/:section'), + ], + ), + TypedStatefulShellBranch( + routes: >[ + TypedGoRoute(path: '/third'), + ], + ), + ], +) +class MainShellRouteData extends StatefulShellRouteData { + const MainShellRouteData(); + + @override + Widget builder( + BuildContext context, + GoRouterState state, + StatefulNavigationShell navigationShell, + ) { + return MainPageView( + navigationShell: navigationShell, + ); + } +} + +class FirstShellBranchData extends StatefulShellBranchData { + const FirstShellBranchData(); +} + +class SecondShellBranchData extends StatefulShellBranchData { + const SecondShellBranchData(); + + static String $initialLocation = '/second/second'; +} + +class ThirdShellBranchData extends StatefulShellBranchData { + const ThirdShellBranchData(); +} + +class FirstRouteData extends GoRouteData { + const FirstRouteData(); + + @override + Widget build(BuildContext context, GoRouterState state) { + return const FirstPageView(label: 'First screen'); + } +} + +enum SecondPageSection { + first, + second, + third, +} + +class SecondRouteData extends GoRouteData { + const SecondRouteData({ + required this.section, + }); + + final SecondPageSection section; + + @override + Widget build(BuildContext context, GoRouterState state) { + return SecondPageView( + section: section, + ); + } +} + +class ThirdRouteData extends GoRouteData { + const ThirdRouteData(); + + @override + Widget build(BuildContext context, GoRouterState state) { + return const ThirdPageView(label: 'Third screen'); + } +} + +class MainPageView extends StatelessWidget { + const MainPageView({ + required this.navigationShell, + Key? key, + }) : super(key: key); + + final StatefulNavigationShell navigationShell; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: navigationShell, + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem(icon: Icon(Icons.home), label: 'First'), + BottomNavigationBarItem(icon: Icon(Icons.favorite), label: 'Second'), + BottomNavigationBarItem(icon: Icon(Icons.list), label: 'Third'), + ], + currentIndex: navigationShell.currentIndex, + onTap: (int index) => _onTap(context, index), + ), + ); + } + + void _onTap(BuildContext context, int index) { + navigationShell.goBranch( + index, + initialLocation: index == navigationShell.currentIndex, + ); + } +} + +class FirstPageView extends StatelessWidget { + const FirstPageView({ + required this.label, + super.key, + }); + + final String label; + + @override + Widget build(BuildContext context) { + return Center( + child: Text(label), + ); + } +} + +class SecondPageView extends StatelessWidget { + const SecondPageView({ + super.key, + required this.section, + }); + + final SecondPageSection section; + + @override + Widget build(BuildContext context) { + return DefaultTabController( + length: 3, + initialIndex: SecondPageSection.values.indexOf(section), + child: Column( + children: [ + TabBar( + tabs: [ + Tab( + child: Text( + 'First', + style: TextStyle(color: Colors.black87), + ), + ), + Tab( + child: Text( + 'Second', + style: TextStyle(color: Colors.black87), + ), + ), + Tab( + child: Text( + 'Third', + style: TextStyle(color: Colors.black87), + ), + ), + ], + onTap: (index) { + _onTap(context, index); + }, + ), + Expanded( + child: TabBarView( + children: [ + SecondSubPageView( + label: 'First', + ), + SecondSubPageView( + label: 'Second', + ), + SecondSubPageView( + label: 'Third', + ), + ], + ), + ), + ], + ), + ); + } +} + +void _onTap(BuildContext context, index) {} + +class SecondSubPageView extends StatelessWidget { + const SecondSubPageView({ + required this.label, + super.key, + }); + + final String label; + + @override + Widget build(BuildContext context) { + return Center( + child: Text(label), + ); + } +} + +class ThirdPageView extends StatelessWidget { + const ThirdPageView({ + required this.label, + super.key, + }); + + final String label; + + @override + Widget build(BuildContext context) { + return Center( + child: Text(label), + ); + } +} diff --git a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart new file mode 100644 index 00000000000..1c58d6d7f06 --- /dev/null +++ b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart @@ -0,0 +1,116 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: always_specify_types, public_member_api_docs + +part of 'stateful_shell_route_initial_location_example.dart'; + +// ************************************************************************** +// GoRouterGenerator +// ************************************************************************** + +List get $appRoutes => [ + $mainShellRouteData, + ]; + +RouteBase get $mainShellRouteData => StatefulShellRouteData.$route( + factory: $MainShellRouteDataExtension._fromState, + branches: [ + StatefulShellBranchData.$branch( + routes: [ + GoRouteData.$route( + path: '/first', + factory: $FirstRouteDataExtension._fromState, + ), + ], + ), + StatefulShellBranchData.$branch( + initialLocation: SecondShellBranchData.$initialLocation, + routes: [ + GoRouteData.$route( + path: '/second/:section', + factory: $SecondRouteDataExtension._fromState, + ), + ], + ), + StatefulShellBranchData.$branch( + routes: [ + GoRouteData.$route( + path: '/third', + factory: $ThirdRouteDataExtension._fromState, + ), + ], + ), + ], + ); + +extension $MainShellRouteDataExtension on MainShellRouteData { + static MainShellRouteData _fromState(GoRouterState state) => + const MainShellRouteData(); +} + +extension $FirstRouteDataExtension on FirstRouteData { + static FirstRouteData _fromState(GoRouterState state) => + const FirstRouteData(); + + String get location => GoRouteData.$location( + '/first', + ); + + void go(BuildContext context) => context.go(location); + + Future push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); + + void replace(BuildContext context) => context.replace(location); +} + +extension $SecondRouteDataExtension on SecondRouteData { + static SecondRouteData _fromState(GoRouterState state) => SecondRouteData( + section: _$SecondPageSectionEnumMap + ._$fromName(state.pathParameters['section']!), + ); + + String get location => GoRouteData.$location( + '/second/${Uri.encodeComponent(_$SecondPageSectionEnumMap[section]!)}', + ); + + void go(BuildContext context) => context.go(location); + + Future push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); + + void replace(BuildContext context) => context.replace(location); +} + +const _$SecondPageSectionEnumMap = { + SecondPageSection.first: 'first', + SecondPageSection.second: 'second', + SecondPageSection.third: 'third', +}; + +extension $ThirdRouteDataExtension on ThirdRouteData { + static ThirdRouteData _fromState(GoRouterState state) => + const ThirdRouteData(); + + String get location => GoRouteData.$location( + '/third', + ); + + void go(BuildContext context) => context.go(location); + + Future push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); + + void replace(BuildContext context) => context.replace(location); +} + +extension on Map { + T _$fromName(String value) => + entries.singleWhere((element) => element.value == value).key; +} From 072315a610e3ff70db9c94a550ef62b876d8641e Mon Sep 17 00:00:00 2001 From: GeekAbdelouahed Date: Mon, 18 Sep 2023 20:49:26 +0100 Subject: [PATCH 5/8] feat: add widget test for stateful shell route initial location example --- ..._shell_route_initial_location_example.dart | 115 ++++++++++-------- ...hell_route_initial_location_example.g.dart | 46 +++---- ...ful_shell_route_initial_location_test.dart | 20 +++ 3 files changed, 108 insertions(+), 73 deletions(-) create mode 100644 packages/go_router_builder/example/test/stateful_shell_route_initial_location_test.dart diff --git a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart index 79e9942964f..ed9f047830f 100644 --- a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart +++ b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart @@ -19,7 +19,7 @@ class App extends StatelessWidget { final GoRouter _router = GoRouter( routes: $appRoutes, - initialLocation: '/first', + initialLocation: '/home', ); } @@ -34,19 +34,25 @@ class HomeScreen extends StatelessWidget { @TypedStatefulShellRoute( branches: >[ - TypedStatefulShellBranch( + TypedStatefulShellBranch( routes: >[ - TypedGoRoute(path: '/first'), + TypedGoRoute( + path: '/home', + ), ], ), - TypedStatefulShellBranch( + TypedStatefulShellBranch( routes: >[ - TypedGoRoute(path: '/second/:section'), + TypedGoRoute( + path: '/notifications/:section', + ), ], ), - TypedStatefulShellBranch( + TypedStatefulShellBranch( routes: >[ - TypedGoRoute(path: '/third'), + TypedGoRoute( + path: '/orders', + ), ], ), ], @@ -66,56 +72,56 @@ class MainShellRouteData extends StatefulShellRouteData { } } -class FirstShellBranchData extends StatefulShellBranchData { - const FirstShellBranchData(); +class HomeShellBranchData extends StatefulShellBranchData { + const HomeShellBranchData(); } -class SecondShellBranchData extends StatefulShellBranchData { - const SecondShellBranchData(); +class NotificationsShellBranchData extends StatefulShellBranchData { + const NotificationsShellBranchData(); - static String $initialLocation = '/second/second'; + static String $initialLocation = '/notifications/old'; } -class ThirdShellBranchData extends StatefulShellBranchData { - const ThirdShellBranchData(); +class OrdersShellBranchData extends StatefulShellBranchData { + const OrdersShellBranchData(); } -class FirstRouteData extends GoRouteData { - const FirstRouteData(); +class HomeRouteData extends GoRouteData { + const HomeRouteData(); @override Widget build(BuildContext context, GoRouterState state) { - return const FirstPageView(label: 'First screen'); + return const HomePageView(label: 'Home page'); } } -enum SecondPageSection { - first, - second, - third, +enum NotificationsPageSection { + latest, + old, + archive, } -class SecondRouteData extends GoRouteData { - const SecondRouteData({ +class NotificationsRouteData extends GoRouteData { + const NotificationsRouteData({ required this.section, }); - final SecondPageSection section; + final NotificationsPageSection section; @override Widget build(BuildContext context, GoRouterState state) { - return SecondPageView( + return NotificationsPageView( section: section, ); } } -class ThirdRouteData extends GoRouteData { - const ThirdRouteData(); +class OrdersRouteData extends GoRouteData { + const OrdersRouteData(); @override Widget build(BuildContext context, GoRouterState state) { - return const ThirdPageView(label: 'Third screen'); + return const OrdersPageView(label: 'Orders page'); } } @@ -134,9 +140,18 @@ class MainPageView extends StatelessWidget { body: navigationShell, bottomNavigationBar: BottomNavigationBar( items: const [ - BottomNavigationBarItem(icon: Icon(Icons.home), label: 'First'), - BottomNavigationBarItem(icon: Icon(Icons.favorite), label: 'Second'), - BottomNavigationBarItem(icon: Icon(Icons.list), label: 'Third'), + BottomNavigationBarItem( + icon: Icon(Icons.home), + label: 'Home', + ), + BottomNavigationBarItem( + icon: Icon(Icons.favorite), + label: 'Notifications', + ), + BottomNavigationBarItem( + icon: Icon(Icons.list), + label: 'Orders', + ), ], currentIndex: navigationShell.currentIndex, onTap: (int index) => _onTap(context, index), @@ -152,8 +167,8 @@ class MainPageView extends StatelessWidget { } } -class FirstPageView extends StatelessWidget { - const FirstPageView({ +class HomePageView extends StatelessWidget { + const HomePageView({ required this.label, super.key, }); @@ -168,38 +183,38 @@ class FirstPageView extends StatelessWidget { } } -class SecondPageView extends StatelessWidget { - const SecondPageView({ +class NotificationsPageView extends StatelessWidget { + const NotificationsPageView({ super.key, required this.section, }); - final SecondPageSection section; + final NotificationsPageSection section; @override Widget build(BuildContext context) { return DefaultTabController( length: 3, - initialIndex: SecondPageSection.values.indexOf(section), + initialIndex: NotificationsPageSection.values.indexOf(section), child: Column( children: [ TabBar( tabs: [ Tab( child: Text( - 'First', + 'Latest', style: TextStyle(color: Colors.black87), ), ), Tab( child: Text( - 'Second', + 'Old', style: TextStyle(color: Colors.black87), ), ), Tab( child: Text( - 'Third', + 'Archive', style: TextStyle(color: Colors.black87), ), ), @@ -211,14 +226,14 @@ class SecondPageView extends StatelessWidget { Expanded( child: TabBarView( children: [ - SecondSubPageView( - label: 'First', + NotificationsSubPageView( + label: 'Latest notifications', ), - SecondSubPageView( - label: 'Second', + NotificationsSubPageView( + label: 'Old notifications', ), - SecondSubPageView( - label: 'Third', + NotificationsSubPageView( + label: 'Archived notifications', ), ], ), @@ -231,8 +246,8 @@ class SecondPageView extends StatelessWidget { void _onTap(BuildContext context, index) {} -class SecondSubPageView extends StatelessWidget { - const SecondSubPageView({ +class NotificationsSubPageView extends StatelessWidget { + const NotificationsSubPageView({ required this.label, super.key, }); @@ -247,8 +262,8 @@ class SecondSubPageView extends StatelessWidget { } } -class ThirdPageView extends StatelessWidget { - const ThirdPageView({ +class OrdersPageView extends StatelessWidget { + const OrdersPageView({ required this.label, super.key, }); diff --git a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart index 1c58d6d7f06..5b398e07990 100644 --- a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart +++ b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart @@ -18,25 +18,25 @@ RouteBase get $mainShellRouteData => StatefulShellRouteData.$route( StatefulShellBranchData.$branch( routes: [ GoRouteData.$route( - path: '/first', - factory: $FirstRouteDataExtension._fromState, + path: '/home', + factory: $HomeRouteDataExtension._fromState, ), ], ), StatefulShellBranchData.$branch( - initialLocation: SecondShellBranchData.$initialLocation, + initialLocation: NotificationsShellBranchData.$initialLocation, routes: [ GoRouteData.$route( - path: '/second/:section', - factory: $SecondRouteDataExtension._fromState, + path: '/notifications/:section', + factory: $NotificationsRouteDataExtension._fromState, ), ], ), StatefulShellBranchData.$branch( routes: [ GoRouteData.$route( - path: '/third', - factory: $ThirdRouteDataExtension._fromState, + path: '/orders', + factory: $OrdersRouteDataExtension._fromState, ), ], ), @@ -48,12 +48,11 @@ extension $MainShellRouteDataExtension on MainShellRouteData { const MainShellRouteData(); } -extension $FirstRouteDataExtension on FirstRouteData { - static FirstRouteData _fromState(GoRouterState state) => - const FirstRouteData(); +extension $HomeRouteDataExtension on HomeRouteData { + static HomeRouteData _fromState(GoRouterState state) => const HomeRouteData(); String get location => GoRouteData.$location( - '/first', + '/home', ); void go(BuildContext context) => context.go(location); @@ -66,14 +65,15 @@ extension $FirstRouteDataExtension on FirstRouteData { void replace(BuildContext context) => context.replace(location); } -extension $SecondRouteDataExtension on SecondRouteData { - static SecondRouteData _fromState(GoRouterState state) => SecondRouteData( - section: _$SecondPageSectionEnumMap +extension $NotificationsRouteDataExtension on NotificationsRouteData { + static NotificationsRouteData _fromState(GoRouterState state) => + NotificationsRouteData( + section: _$NotificationsPageSectionEnumMap ._$fromName(state.pathParameters['section']!), ); String get location => GoRouteData.$location( - '/second/${Uri.encodeComponent(_$SecondPageSectionEnumMap[section]!)}', + '/notifications/${Uri.encodeComponent(_$NotificationsPageSectionEnumMap[section]!)}', ); void go(BuildContext context) => context.go(location); @@ -86,18 +86,18 @@ extension $SecondRouteDataExtension on SecondRouteData { void replace(BuildContext context) => context.replace(location); } -const _$SecondPageSectionEnumMap = { - SecondPageSection.first: 'first', - SecondPageSection.second: 'second', - SecondPageSection.third: 'third', +const _$NotificationsPageSectionEnumMap = { + NotificationsPageSection.latest: 'latest', + NotificationsPageSection.old: 'old', + NotificationsPageSection.archive: 'archive', }; -extension $ThirdRouteDataExtension on ThirdRouteData { - static ThirdRouteData _fromState(GoRouterState state) => - const ThirdRouteData(); +extension $OrdersRouteDataExtension on OrdersRouteData { + static OrdersRouteData _fromState(GoRouterState state) => + const OrdersRouteData(); String get location => GoRouteData.$location( - '/third', + '/orders', ); void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/example/test/stateful_shell_route_initial_location_test.dart b/packages/go_router_builder/example/test/stateful_shell_route_initial_location_test.dart new file mode 100644 index 00000000000..6e819bf7303 --- /dev/null +++ b/packages/go_router_builder/example/test/stateful_shell_route_initial_location_test.dart @@ -0,0 +1,20 @@ +// 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_test/flutter_test.dart'; +import 'package:go_router_builder_example/stateful_shell_route_initial_location_example.dart'; + +void main() { + testWidgets( + 'Navigate to Notifications section with old tab selected by default', + (WidgetTester tester) async { + await tester.pumpWidget(App()); + expect(find.text('Home'), findsOneWidget); + + await tester.tap(find.text('Notifications')); + await tester.pumpAndSettle(); + expect(find.text('Old notifications'), findsOneWidget); + }, + ); +} From 7c4250046a73b196698d47a0cf519d5b9c820827 Mon Sep 17 00:00:00 2001 From: GeekAbdelouahed Date: Mon, 18 Sep 2023 21:51:10 +0100 Subject: [PATCH 6/8] chore: update pubspec.yaml --- packages/go_router_builder/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index da788c9d187..cf48de720f0 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -2,7 +2,7 @@ name: go_router_builder description: >- A builder that supports generated strongly-typed route helpers for package:go_router -version: 2.3.2 +version: 2.3.3 repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22 From 547465721cb993e298b2de48006974b3af31627d Mon Sep 17 00:00:00 2001 From: GeekAbdelouahed Date: Mon, 18 Sep 2023 22:24:29 +0100 Subject: [PATCH 7/8] feat: ignore public_member_api_docs --- ..._shell_route_initial_location_example.dart | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart index ed9f047830f..63c16638e7b 100644 --- a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart +++ b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ignore_for_file: public_member_api_docs + import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; @@ -128,8 +130,8 @@ class OrdersRouteData extends GoRouteData { class MainPageView extends StatelessWidget { const MainPageView({ required this.navigationShell, - Key? key, - }) : super(key: key); + super.key, + }); final StatefulNavigationShell navigationShell; @@ -196,10 +198,10 @@ class NotificationsPageView extends StatelessWidget { return DefaultTabController( length: 3, initialIndex: NotificationsPageSection.values.indexOf(section), - child: Column( - children: [ + child: const Column( + children: [ TabBar( - tabs: [ + tabs: [ Tab( child: Text( 'Latest', @@ -219,13 +221,10 @@ class NotificationsPageView extends StatelessWidget { ), ), ], - onTap: (index) { - _onTap(context, index); - }, ), Expanded( child: TabBarView( - children: [ + children: [ NotificationsSubPageView( label: 'Latest notifications', ), @@ -244,8 +243,6 @@ class NotificationsPageView extends StatelessWidget { } } -void _onTap(BuildContext context, index) {} - class NotificationsSubPageView extends StatelessWidget { const NotificationsSubPageView({ required this.label, From f148d4743abf2b938a70964066bc6bd2a2acf5f0 Mon Sep 17 00:00:00 2001 From: GeekAbdelouahed Date: Mon, 18 Sep 2023 22:26:48 +0100 Subject: [PATCH 8/8] feat: update stefull shell branch test --- .../test_inputs/statefull_shell_branch_data.dart.expect | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect b/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect index a1c77bf4c55..07b95b1deeb 100644 --- a/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect +++ b/packages/go_router_builder/test_inputs/statefull_shell_branch_data.dart.expect @@ -1,3 +1,3 @@ RouteBase get $shellRouteBranchData => StatefulShellBranchData.$branch( initialLocation: ShellRouteBranchData.$initialLocation, - ); \ No newline at end of file + );