Repository navigation
[go_router] requestFocus not passed to Navigator in build #166972
Copy link
Copy link
Closed
flutter/packages
#9177Closed
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.p: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.
Description
Steps to reproduce
The GoRouter class has a requestFocus property that should be passed all the way down to the Navigator constructor. Currently this is not used, so the following behaviour does not apply:
/// Whether or not the navigator created by this builder and it's new topmost route should request focus
/// when the new route is pushed onto the navigator.
///
/// Defaults to true.
final bool requestFocus;
RouterBuilder (builder.dart) does not pass requestFocus to the new Navigator in build.
Expected results
child: Navigator(
key: widget.navigatorKey,
requestFocus: widget.requestFocus,
restorationScopeId: widget.navigatorRestorationId,
pages: _pages!,
observers: widget.observers,
onPopPage: _handlePopPage,
),Actual results
child: Navigator(
key: widget.navigatorKey,
restorationScopeId: widget.navigatorRestorationId,
pages: _pages!,
observers: widget.observers,
onPopPage: _handlePopPage,
),Code sample
Code sample
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() {
debugFocusChanges = true;
runApp(MyApp());
}
final GoRouter _router = GoRouter(
requestFocus: false,
routes: [
GoRoute(
path: '/',
builder: (context, state) => const HomeScreen(),
),
],
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: _router,
title: 'GoRouter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Home')),
body: const Center(child: Text('Welcome to the Home Screen!')),
);
}
}Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[Paste your output here]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.p: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.
Activity
maheshj01 commentedon Apr 12, 2025
Hey @GreatTux,
I am not really sure I understood the issue, I am not quite sure how GoRouter.requestFocus related to navigator.requestFocus. I would suggest updating the issue description
GreatTux commentedon Apr 12, 2025
Hi @maheshj01
This is in the description. GoRouter has a "requestFocus" property, this can be true or false (true by default) but this flag is not applied. It's supposed to be passed to the Navigator created by the RouterBuilder.
maheshj01 commentedon Apr 14, 2025
Thank you for the clarification.
[go_router] Fix requestFocus propagation to Navigator (#9177)
github-actions commentedon May 22, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.