NoSuchMethodError: попытка вызвать не-функцию, например null: 'dart.global.firebase.auth' - PullRequest
2 голосов
/ 05 августа 2020

Новое во Flutter. Я подозреваю, что я упустил кое-что очень простое, когда пытался настроить Firebase Auth. Большинство просят вас дважды проверить, что firebase-auth. js правильно включен в файл index. html. Это сделано, index. html файл ниже.

Этот пост и этот пост указывают на то, что эту проблему можно решить, переместив мою конфигурацию firebase в голову в файле index. html. Не уверен, почему это так, но попробовал и не увидел никаких изменений.

мой index. html файл:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter application.">

  <!-- 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_auth">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="shortcut icon" type="image/png" href="favicon.png"/>

  <title>test_auth</title>
  <link rel="manifest" href="manifest.json">

</head>
<body>

  <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('load', function () {
        navigator.serviceWorker.register('flutter_service_worker.js');
      });
    }
  </script>

  <!-- Firebase Configuration-->
  <!-- The core Firebase JS SDK is always required and must be listed first -->
  <script src="https://www.gstatic.com/firebasejs/7.17.1/firebase-app.js"></script>

  <!-- TODO: Add SDKs for Firebase products that you want to use
      https://firebase.google.com/docs/web/setup#available-libraries -->
  <script src="https://www.gstatic.com/firebase/7.17.1/firebase-auth.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.17.1/firebase-firestore.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.17.1/firebase-analytics.js"></script>

  <script>
      var firebaseConfig = {
        //my deets
      };
      // Initialize Firebase
      firebase.initializeApp(firebaseConfig);
      firebase.analytics();
      firebase.auth();
      </script>
  <!-- End of Firebase Configuration-->

  <script src="main.dart.js" type="application/javascript"></script>


</body>
</html>

my pubspe c .yaml зависимости:

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.3
  firebase_core: ^0.4.5
  firebase_auth: ^0.16.1
  cloud_firestore: ^0.13.7
    flutter doctor -v
[✓] Flutter (Channel master, 1.21.0-6.0.pre.170, on Mac OS X 10.15.2 19C57, locale en-CA)
    • Flutter version 1.21.0-6.0.pre.170 at /Users/olisno/development/flutter
    • Framework revision 4c7fae93aa (6 hours ago), 2020-08-04 10:44:43 -0700
    • Engine revision 033dd45607
    • Dart version 2.10.0 (build 2.10.0-2.0.dev 0f0e04ec3a)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at /Users/olisno/Library/Android/sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.6, Build version 11E708
    • CocoaPods version 1.9.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.47.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.12.2

[✓] Connected device (3 available)
    • iPhone SE (2nd generation) (mobile) • 7F1F5A6D-F82D-46FB-B71B-371887713467 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)
    • Web Server (web)                    • web-server                           • web-javascript • Flutter Tools
    • Chrome (web)                        • chrome                               • web-javascript • Google Chrome 84.0.4147.105

• No issues found!

Спасибо за любые подсказки!

...