skip to Main Content

after upgrading flutter to 3.24 I created a brand new application and run it on chrome I am getting this exception in console

The following JSNoSuchMethodError was thrown building NotificationListener<NavigationNotification>:
TypeError: Cannot read properties of undefined (reading 'mapEquals')

The relevant error-causing widget was:
  MaterialApp
  MaterialApp:file:///C:/Users/Munsif%20Ali/Desktop/Optemas/referee_dashboard/lib/main.dart:14:18

When the exception was thrown, this was the stack:
packages/flutter/src/widgets/shortcuts.dart 834:10                       set shortcuts
shortcuts.dart:834
packages/flutter/src/widgets/shortcuts.dart 1076:7                       initState
shortcuts.dart:1076
packages/flutter/src/widgets/framework.dart 5748:55                      [_firstBuild]
framework.dart:5748
packages/flutter/src/widgets/framework.dart 5593:5                       mount
framework.dart:5593
packages/flutter/src/widgets/framework.dart 4468:15                      inflateWidget
framework.dart:4468
packages/flutter/src/widgets/framework.dart 3963:18                      updateChild
framework.dart:3963
packages/flutter/src/widgets/framework.dart 5642:16                      performRebuild
framework.dart:5642
packages/flutter/src/widgets/framework.dart 5333:7                       rebuild
framework.dart:5333
packages/flutter/src/widgets/framework.dart 5599:5                       [_firstBuild]
framework.dart:5599
packages/flutter/src/widgets/framework.dart 5593:5                       mount
framework.dart:5593
packages/flutter/src/widgets/framework.dart 4468:15                      inflateWidget
framework.dart:4468
packages/flutter/src/widgets/framework.dart 3963:18                      updateChild
framework.dart:3963
packages/flutter/src/widgets/framework.dart 5642:16                      performRebuild
framework.dart:5642
packages/flutter/src/widgets/framework.dart 5333:7                       rebuild
framework.dart:5333
packages/flutter/src/widgets/framework.dart 5599:5                       [_firstBuild]
framework.dart:5599
packages/flutter/src/widgets/framework.dart 5593:5                       mount
framework.dart:5593
packages/flutter/src/widgets/framework.dart 4468:15                      inflateWidget
framework.dart:4468
packages/flutter/src/widgets/framework.dart 3963:18                      updateChild
framework.dart:3963
packages/flutter/src/widgets/framework.dart 5642:16                      performRebuild
framework.dart:5642
packages/flutter/src/widgets/framework.dart 5780:11                      performRebuild
framework.dart:5780
packages/flutter/src/widgets/framework.dart 5333:7                       rebuild
framework.dart:5333
packages/flutter/src/widgets/framework.dart 5599:5                       [_firstBuild]
framework.dart:5599
packages/flutter/src/widgets/framework.dart 5771:11                      [_firstBuild]
framework.dart:5771
packages/flutter/src/widgets/framework.dart 5593:5                       mount
framework.dart:5593
packages/flutter/src/widgets/framework.dart 4468:15                      inflateWidget
framework.dart:4468
packages/flutter/src/widgets/framework.dart 3963:18                      updateChild
framework.dart:3963
packages/flutter/src/widgets/framework.dart 5642:16                      performRebuild
framework.dart:5642
packages/flutter/src/widgets/framework.dart 5333:7                       rebuild
framework.dart:5333
packages/flutter/src/widgets/framework.dart 5599:5                       [_firstBuild]
framework.dart:5599
packages/flutter/src/widgets/framework.dart 5593:5                       mount
framework.dart:5593
packages/flutter/src/widgets/framework.dart 4468:15                      inflateWidget
framework.dart:4468
packages/flutter/src/widgets/framework.dart 3963:18                      updateChild
framework.dart:3963
packages/flutter/src/widgets/framework.dart 5642:16                      performRebuild
framework.dart:5642
packages/flutter/src/widgets/framework.dart 5780:11                      performRebuild
framework.dart:5780
packages/flutter/src/widgets/framework.dart 5333:7                       rebuild
framework.dart:5333
packages/flutter/src/widgets/framework.dart 5599:5                       [_firstBuild]
framework.dart:5599
packages/flutter/src/widgets/framework.dart 5771:11                      [_firstBuild]
framework.dart:5771
packages/flutter/src/widgets/framework.dart 5593:5                       mount
framework.dart:5593
packages/flutter/src/widgets/framework.dart 4468:15                      inflateWidget
framework.dart:4468
packages/flutter/src/widgets/framework.dart 3963:18                      updateChild
framework.dart:3963
packages/flutter/src/widgets/framework.dart 5642:16                      performRebuild
framework.dart:5642
packages/flutter/src/widgets/framework.dart 5333:7                       rebuild
framework.dart:5333
packages/flutter/src/widgets/framework.dart 5599:5                       [_firstBuild]
framework.dart:5599
packages/flutter/src/widgets/framework.dart 5593:5                       mount
framework.dart:5593
packages/flutter/src/widgets/framework.dart 4468:15                      inflateWidget
framework.dart:4468
packages/flutter/src/widgets/framework.dart 3963:18                      updateChild
framework.dart:3963
packages/flutter/src/widgets/framework.dart 5642:16                      performRebuild
framework.dart:5642
packages/flutter/src/widgets/framework.dart 5780:11    

here is app code

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Home(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Hello World'),
      ),
      body: const Center(
        child: Text('Hello World'),
      ),
    );
  }
}

enter image description here

2

Answers


  1. The app has to work if you remove WidgetsFlutterBinding.ensureInitialized();

    But how to avoid removing ensureInitialized I don’t know yet.

    Login or Signup to reply.
  2. I have the same problem – but in fact I get different errors: both JSNoSuchMethodError and TypeError, but also, for example.

    Reject promise with error: TypeError: unable to read undefined property (read 'SharedPreferencesPlugin')
    

    or

    The message on the flutter/lifecycle channel was rejected before it could be handled.
    This happens when the plugin sends messages to the framework page before the framework has had a chance to register a listener. See the ChannelBuffers API documentation to learn how to configure the channel to expect more messages or to expect message rejection:
    https://api.flutter.dev/flutter/dart-ui/ChannelBuffers-class.html
    

    From what I’ve noticed the problem is in Flutter’s preparation of the web platform in the /web directory. I tried flutter clean and flutter pub cache clean. I even created a new ‘Hello World’ project without external dependencies. All to no effect. The only thing that helped was swapping the contents of the PROJECT_DIR/web/index.html file:

    <!DOCTYPE html>
    <html>
    <head>
      <!--
        If you are serving your web app in a path other than the root, change the
        href value below to reflect the base path you are serving from.
    
        The path provided below has to start and end with a slash "/" in order for
        it to work correctly.
    
        For more details:
        * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
    
        This is a placeholder for base href that will be replaced by the value of
        the `--base-href` argument provided to `flutter build`.
      -->
      <base href="$FLUTTER_BASE_HREF">
    
      <meta charset="UTF-8">
      <meta content="IE=Edge" http-equiv="X-UA-Compatible">
      <meta name="description" content="A new Flutter project.">
    
      <!-- iOS meta tags & icons -->
      <meta name="apple-mobile-web-app-capable" content="yes">
      <meta name="apple-mobile-web-app-status-bar-style" content="black">
      <meta name="apple-mobile-web-app-title" content="test_app">
      <link rel="apple-touch-icon" href="icons/Icon-192.png">
    
      <!-- Favicon -->
      <link rel="icon" type="image/png" href="favicon.png"/>
    
      <title>test_app</title>
      <link rel="manifest" href="manifest.json">
    </head>
    <body>
      <script src="flutter_bootstrap.js" async></script>
    </body>
    </html>
    

    , to the old [deprecated] version:

    <!DOCTYPE html>
    <html>
    <head>
        <!--
          If you are serving your web app in a path other than the root, change the
          href value below to reflect the base path you are serving from.
    
          The path provided below has to start and end with a slash "/" in order for
          it to work correctly.
    
          For more details:
          * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
    
          This is a placeholder for base href that will be replaced by the value of
          the `--base-href` argument provided to `flutter build`.
        -->
        <base href="$FLUTTER_BASE_HREF">
    
        <meta charset="UTF-8">
        <meta content="IE=Edge" http-equiv="X-UA-Compatible">
        <meta content="A new Flutter project." name="description">
    
        <!-- iOS meta tags & icons -->
        <meta content="yes" name="apple-mobile-web-app-capable">
        <meta content="black" name="apple-mobile-web-app-status-bar-style">
        <meta content="wheelio" name="apple-mobile-web-app-title">
        <link href="icons/Icon-192.png" rel="apple-touch-icon">
    
        <!-- Favicon -->
        <link href="favicon.png" rel="icon" type="image/png"/>
    
        <title>wheelio</title>
        <link href="manifest.json" rel="manifest">
    
        <script>
            // The value below is injected by flutter build, do not touch.
            const serviceWorkerVersion = null;
        </script>
        <!-- This script adds the flutter initialization JS code -->
        <script defer src="flutter.js"></script>
    </head>
    <body>
    <script>
        window.addEventListener('load', function(ev) {
          // Download main.dart.js
          _flutter.loader.loadEntrypoint({
            serviceWorker: {
              serviceWorkerVersion: serviceWorkerVersion,
            },
            onEntrypointLoaded: function(engineInitializer) {
              engineInitializer.initializeEngine().then(function(appRunner) {
                appRunner.runApp();
              });
            }
          });
        });
    </script>
    </body>
    </html>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search