[go_router_builder] Add push method to `route_config` generated extension (#1941)

Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md
index 1e47d14..1b1cb10 100644
--- a/packages/go_router_builder/CHANGELOG.md
+++ b/packages/go_router_builder/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.0.4
+
+- Adds `push` method to generated GoRouteData's extension. [#103025](https://github.com/flutter/flutter/issues/103025)
+
 ## 1.0.3
 
 - Fixes incorrect separator at location path on Windows. [#102710](https://github.com/flutter/flutter/issues/102710)
diff --git a/packages/go_router_builder/example/lib/all_types.g.dart b/packages/go_router_builder/example/lib/all_types.g.dart
index be1d211..2643537 100644
--- a/packages/go_router_builder/example/lib/all_types.g.dart
+++ b/packages/go_router_builder/example/lib/all_types.g.dart
@@ -65,6 +65,8 @@
       );
 
   void go(BuildContext context) => context.go(location, extra: this);
+
+  void push(BuildContext context) => context.push(location, extra: this);
 }
 
 const _$PersonDetailsEnumMap = {
diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart
index 220aaa0..d5ce078 100644
--- a/packages/go_router_builder/example/lib/main.dart
+++ b/packages/go_router_builder/example/lib/main.dart
@@ -155,12 +155,17 @@
     return Scaffold(
       appBar: AppBar(
         title: const Text(App.title),
+        centerTitle: true,
         actions: <Widget>[
+          ElevatedButton(
+            onPressed: () => const HomeRoute().push(context),
+            child: const Text('Push home'),
+          ),
           IconButton(
             onPressed: info.logout,
             tooltip: 'Logout: ${info.userName}',
             icon: const Icon(Icons.logout),
-          )
+          ),
         ],
       ),
       body: ListView(
diff --git a/packages/go_router_builder/example/lib/main.g.dart b/packages/go_router_builder/example/lib/main.g.dart
index 50931d5..0f87baa 100644
--- a/packages/go_router_builder/example/lib/main.g.dart
+++ b/packages/go_router_builder/example/lib/main.g.dart
@@ -44,6 +44,8 @@
       );
 
   void go(BuildContext context) => context.go(location, extra: this);
+
+  void push(BuildContext context) => context.push(location, extra: this);
 }
 
 extension $FamilyRouteExtension on FamilyRoute {
@@ -56,6 +58,8 @@
       );
 
   void go(BuildContext context) => context.go(location, extra: this);
+
+  void push(BuildContext context) => context.push(location, extra: this);
 }
 
 extension $PersonRouteExtension on PersonRoute {
@@ -69,6 +73,8 @@
       );
 
   void go(BuildContext context) => context.go(location, extra: this);
+
+  void push(BuildContext context) => context.push(location, extra: this);
 }
 
 extension $PersonDetailsRouteExtension on PersonDetailsRoute {
@@ -85,6 +91,8 @@
       );
 
   void go(BuildContext context) => context.go(location, extra: this);
+
+  void push(BuildContext context) => context.push(location, extra: this);
 }
 
 const _$PersonDetailsEnumMap = {
@@ -116,4 +124,6 @@
       );
 
   void go(BuildContext context) => context.go(location, extra: this);
+
+  void push(BuildContext context) => context.push(location, extra: this);
 }
diff --git a/packages/go_router_builder/example/lib/simple_example.g.dart b/packages/go_router_builder/example/lib/simple_example.g.dart
index 7b78e19..b3ad338 100644
--- a/packages/go_router_builder/example/lib/simple_example.g.dart
+++ b/packages/go_router_builder/example/lib/simple_example.g.dart
@@ -31,6 +31,8 @@
       );
 
   void go(BuildContext context) => context.go(location, extra: this);
+
+  void push(BuildContext context) => context.push(location, extra: this);
 }
 
 extension $FamilyRouteExtension on FamilyRoute {
@@ -43,4 +45,6 @@
       );
 
   void go(BuildContext context) => context.go(location, extra: this);
+
+  void push(BuildContext context) => context.push(location, extra: this);
 }
diff --git a/packages/go_router_builder/example/test/widget_test.dart b/packages/go_router_builder/example/test/widget_test.dart
index 1084092..da8e603 100644
--- a/packages/go_router_builder/example/test/widget_test.dart
+++ b/packages/go_router_builder/example/test/widget_test.dart
@@ -12,6 +12,15 @@
     await tester.tap(find.text('Login'));
     await tester.pumpAndSettle();
 
+    await tester.tap(find.text('Push home'));
+    await tester.pumpAndSettle();
+
+    expect(find.text('Push home'), findsOneWidget);
+    expect(find.text('Push home', skipOffstage: false), findsNWidgets(2));
+
+    await tester.pageBack();
+    await tester.pumpAndSettle();
+
     await tester.tap(find.text('Sells'));
     await tester.pumpAndSettle();
 
diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart
index 1e5f440..76aa515 100644
--- a/packages/go_router_builder/lib/src/route_config.dart
+++ b/packages/go_router_builder/lib/src/route_config.dart
@@ -140,7 +140,9 @@
   String get location => GoRouteData.\$location($_locationArgs,$_locationQueryParams);
 
   void go(BuildContext context) => context.go(location, extra: this);
-}
+
+  void push(BuildContext context) => context.push(location, extra: this);
+} 
 ''';
 
   /// Returns this [RouteConfig] and all child [RouteConfig] instances.
diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml
index 579497b..0bca37b 100644
--- a/packages/go_router_builder/pubspec.yaml
+++ b/packages/go_router_builder/pubspec.yaml
@@ -2,7 +2,7 @@
 description: >-
   A builder that supports generated strongly-typed route helpers for
   package:go_router
-version: 1.0.3
+version: 1.0.4
 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