Skip to content

[go_router] requestFocus not passed to Navigator in build #166972

Closed
flutter/packages
#9177

Description

@GreatTux

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]

Activity

  1. maheshj01 commented on Apr 12, 2025

    @maheshj01
    Member

    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

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 12, 2025
  3. GreatTux commented on Apr 12, 2025

    @GreatTux
    Author

    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.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 12, 2025
  5. maheshj01 commented on Apr 14, 2025

    @maheshj01
    Member

    Thank you for the clarification.

  6. added
    packageflutter/packages repository. See also p: labels.
    c: proposalA detailed proposal for a change to Flutter
    f: routesNavigator, Router, and related APIs.
    and removed
    in triagePresently being triaged by the triage team
    on Apr 14, 2025
  7. github-actions commented on May 22, 2025

    @github-actions

    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 -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterf: routesNavigator, Router, and related APIs.p: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions