Skip to content

PopScope breaks willHandlePopInternally and didpop #134752

@chunhtai

Description

@chunhtai

Is there an existing issue for this?

Steps to reproduce

Run the test

Expected results

test passes.

Actual results

The test fails, which means willHandlePopInternally return true but didPop also return true. According to the doc https://api.flutter.dev/flutter/widgets/Route/willHandlePopInternally.html, the willHandlePopInternally should return the inverse of didpop.

Code sample

Code sample
testWidgets('ModalRoute must comply with willHandlePopInternally when there is a PopScope', (WidgetTester tester) async {
      const List<Page<void>> myPages = <Page<void>>[
        MaterialPage<void>(child: Text('page1')),
        MaterialPage<void>(
          child: PopScope(
            canPop: false,
            child: Text('page2'),
          ),
        ),
      ];
      await tester.pumpWidget(
        MediaQuery(
          data: MediaQueryData.fromView(tester.view),
          child: Localizations(
            locale: const Locale('en', 'US'),
            delegates: const <LocalizationsDelegate<dynamic>>[
              DefaultMaterialLocalizations.delegate,
              DefaultWidgetsLocalizations.delegate,
            ],
            child: Navigator(
              pages: myPages,
              onPopPage: (_, __) => false,
            ),
          ),
        ),
      );
      final ModalRoute<void> route = ModalRoute.of(tester.element(find.text('page2')))!;
      expect(route.willHandlePopInternally, true);
      expect(route.didPop(null), false);
    });

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

Labels

P2Important issues not at the top of the work listf: routesNavigator, Router, and related APIs.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions