Skip to content

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

Closed
flutter/packages
#9177
@GreatTux

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]

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.good first issueRelatively approachable for first-time contributorsp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-go_routerOwned by Go Router teamtriaged-go_routerTriaged by Go Router team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions