Skip to content

[Navigation] Popping a nested route while the parent is rebuilding causes a flicker #178570

Description

@Milad-Akarie

Steps to reproduce

1- Run the repro App on iOS
2- Navigate to nested page (Page2) by clicking 'Go to Page 2'
3- click the back arrow to pop (Page2)

Expected results

Nested route transitions out with no flicker or issues.

Actual results

Nested route's transition is interrupted with a weird flicker.

Code sample

Code sample
import 'dart:async';

import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Navigator 2.0 Example',
      home: const OuterScreen(),
    );
  }
}

class OuterScreen extends StatefulWidget {
  const OuterScreen({super.key});

  @override
  State<OuterScreen> createState() => _OuterScreenState();
}

class _OuterScreenState extends State<OuterScreen> {
  int _counter = 0;
  late Timer _timer;

  @override
  void initState() {
    super.initState();
    _timer = Timer.periodic(const Duration(milliseconds: 300), (t) {
      // mimic some external state change
      setState(() => _counter++);
    });
  }

  late final List<Page> _pages = [
    MaterialPage(
      name: 'page-1',
      child: Page1(
        showPage2: () {
          setState(() {
            _pages.add(
              MaterialPage(
                name: 'page-2',
                child: const Page2(),
              ),
            );
          });
        },
      ),
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Outer Route')),
      body: Column(
        children: [
          Expanded(child: Center(child: Text('State rebuild: $_counter'))),
          Expanded(
            child: Container(
              color: Colors.grey,
              margin: const EdgeInsets.all(8.0),
              child: Navigator(
                pages: List.of(_pages),
                onDidRemovePage: (page) {
                  setState(() {
                    _pages.remove(page);
                  });
                },
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    _timer.cancel();
    super.dispose();
  }
}

class Page1 extends StatelessWidget {
  const Page1({super.key, required this.showPage2});

  final VoidCallback showPage2;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Inner Route Page 1')),
      body: Center(
        child: ElevatedButton(
          onPressed: showPage2,
          child: const Text('Go to Page 2'),
        ),
      ),
    );
  }
}

class Page2 extends StatelessWidget {
  const Page2({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      appBar: AppBar(
        title: const Text('Inner Route Page 2'),
        leading: BackButton(
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ),
      body: const Center(child: Text('Inner Route Page 2')),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
ScreenRecording_11-15-2025.12-07-46.PM_1.MP4

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.38.1, on macOS 15.6.1 24G90 darwin-arm64, locale en-TR)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 26.1)
[✓] Chrome - develop for the web
[✓] Connected device (4 available)
[✓] Network resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowf: routesNavigator, Router, and related APIs.found in release: 3.38Found to occur in 3.38found in release: 3.39Found to occur in 3.39frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions