Skip to content

ReadingOrderTraversalPolicy crashes with null nearestCommonDirectionality when Flutter Web window regains focus #186562

Closed

Description

Steps to reproduce

  1. Run any Flutter Web application that contains focusable widgets (e.g. OutlinedButton, TextField)
  2. Click inside the Flutter Web application so it has focus
  3. Click outside the browser tab or switch to another application window
  4. Click back into the Flutter Web application to restore focus
  5. The crash occurs immediately when focus is restored

Expected results

Focus is restored to the Flutter Web application without any error.
The application continues running normally

Actual results

The application crashes with:

DartError: Unexpected null value.
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 274:3       throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 950:18  nullCheck
package/flutter/src/widgets/focus_traversal.dart 1689:90                          _pickNext
package/flutter/src/widgets/focus_traversal.dart 1592:37                          sort
package/flutter/src/widgets/focus_traversal.dart 1713:7                           sortDescendants
package/flutter/src/widgets/focus_traversal.dart 515:55                           _sortAllDescendants
package/flutter/src/widgets/focus_traversal.dart 338:9                            _findInitialFocus
package/flutter/src/widgets/focus_traversal.dart 299:12                           findFirstFocus
package/flutter/src/widgets/view.dart 254:33                                      didChangeViewFocus
package/flutter/src/widgets/binding.dart 1071:15                                  handleViewFocusChanged

The null dereference occurs at focus_traversal.dart line 1689:
_ReadingOrderSortData.sortWithDirectionality(inBandOfTop, nearestCommonDirectionality!);

nearestCommonDirectionality is null at this point because the Directionality
context is not yet available when the engine fires invokeOnViewFocusChange
via the platform dispatcher during window focus restore

Code sample

import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              SizedBox(
                width: 300.0,
                child: TextField(
                  decoration: InputDecoration(
                    labelText: "Enter text",
                    border: OutlineInputBorder(),
                  ),
                ),
              ),
              SizedBox(height: 16.0),
              SizedBox(
                width: 300.0,
                child: TextField(
                  decoration: InputDecoration(
                    labelText: "Enter more text",
                    border: OutlineInputBorder(),
                  ),
                ),
              ),
              SizedBox(height: 16.0),
              OutlinedButton(
                onPressed: () {},
                child: Text("Submit"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

// Steps to reproduce:
// 1. Run with: flutter run -d chrome
// 2. Click inside one of the TextField widgets so it has focus
// 3. Click outside the browser window to another application
// 4. Click back into the browser window to restore focus
// 5. Crash occurs immediately on focus restore

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

DartError: Unexpected null value.
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 274:3       throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 950:18  nullCheck
package:flutter/src/widgets/focus_traversal.dart 1689:90                          _pickNext
package:flutter/src/widgets/focus_traversal.dart 1592:37                          sort
package:flutter/src/widgets/focus_traversal.dart 1713:7                           sortDescendants
package:flutter/src/widgets/focus_traversal.dart 515:55                           _sortAllDescendants
package:flutter/src/widgets/focus_traversal.dart 338:9                            [_findInitialFocus]
package:flutter/src/widgets/focus_traversal.dart 299:12                           findFirstFocus
package:flutter/src/widgets/view.dart 254:33                                      didChangeViewFocus
package:flutter/src/widgets/binding.dart 1071:15                                  handleViewFocusChanged
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 118:77  tear
lib/_engine/engine/platform_dispatcher.dart 1553:5                                invoke1
lib/_engine/engine/platform_dispatcher.dart 203:5                                 invokeOnViewFocusChange
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 118:77  tear
lib/_engine/engine/platform_dispatcher/view_focus_binding.dart 109:23             [_handleFocusChange]
lib/_engine/engine/platform_dispatcher/view_focus_binding.dart 54:5               <fn>
dart-sdk/lib/async/zone.dart 1849:54                                              runUnary
dart-sdk/lib/async/zone.dart 1804:26                                              <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/js_allow_interop_patch.dart 224:27    _callDartFunctionFast1

Flutter Doctor output

PS Q:\flutter_projects\nbs_cc_app_pos> fvm flutter doctor -v
[√] Flutter (Channel stable, 3.38.3, on Microsoft Windows [Version 10.0.26200.8457], locale en-GB) [309ms]
    • Flutter version 3.38.3 on channel stable at C:\Users\Mic\fvm\versions\3.38.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 19074d12f7 (6 months ago), 2025-11-20 17:53:13 -0500
    • Engine revision 13e658725d
    • Dart version 3.10.1
    • DevTools version 2.51.1
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging

[√] Windows Version (Windows 11 or higher, 25H2, 2009) [1,148ms]

[√] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [4.1s]
    • Android SDK at C:\Users\Mic\AppData\Local\Android\sdk
    • Emulator version 36.4.9.0 (build_id 14788078) (CL:N/A)
    • Platform android-36.1, build-tools 36.1.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.10+-14961533-b1163.108)
    • All Android licenses accepted.

[√] Chrome - develop for the web [108ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.14.26) [107ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Professional
    • Visual Studio Professional 2022 version 17.14.36930.0
    • Windows 10 SDK version 10.0.26100.0

[√] Connected device (3 available) [250ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26200.8457]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 148.0.7778.168
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 148.0.3967.54

[√] Network resources [758ms]
    • All expected network resources are available.

• No issues found!

Activity

  1. arslannasrnubistar-cloud commented on May 15, 2026

    @arslannasrnubistar-cloud
    Author

    Hey

    we fix it in the flutter sdk class "package:flutter/src/widgets/focus_traversal.dart" where crash was coming but i would wait to know either any other solution or would you check the code which we added and it resolve runtime crash.

    if (nearestCommonDirectionality == null) {   return topmost; } (this line actually we added and fix crash)
    _ReadingOrderSortData.sortWithDirectionality(inBandOfTop, nearestCommonDirectionality); (this is the line causing runTime crash)
    
  2. saurabh-mirajkar commented on May 18, 2026

    @saurabh-mirajkar
    Contributor

    @arslannasrnubistar-cloud Thanks for the detailed report. It appears to be related to #178109

    I’m unable to reproduce this on the latest Flutter stable (3.41.9) using the provided steps, while the report was filed against 3.38.3.

    Can you please verify whether this still reproduces on the latest stable version and share updated results along with video demonstarting the behaviour?

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    needs repro infoAutomated crash report whose cause isn't yet known
    and removed
    in triagePresently being triaged by the triage team
    on May 18, 2026
  4. arslannasrnubistar-cloud commented on May 20, 2026

    @arslannasrnubistar-cloud
    Author

    @saurabh-mirajkar Sure i will check with the latest version and confirm.

    thanks

    @arslannasrnubistar-cloud Thanks for the detailed report. It appears to be related to #178109

    I’m unable to reproduce this on the latest Flutter stable (3.41.9) using the provided steps, while the report was filed against 3.38.3.

    Can you please verify whether this still reproduces on the latest stable version and share updated results along with video demonstarting the behaviour?

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on May 20, 2026
  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on May 20, 2026
  7. github-actions commented on Jun 10, 2026

    @github-actions

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.

    If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.

    Thanks for your contribution.

  8. github-actions commented on Jul 14, 2026

    @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.

  9. locked as resolved and limited conversation to collaborators on Jul 14, 2026
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

    needs repro infoAutomated crash report whose cause isn't yet knownwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions