dartflutter-dependenciesflutter-testdart-null-safetydart-pub

Flutter @dart=2.9 import 'dart:math'; Error, dart code won't run in emulator?


Question: How can I solve the flutter error as shown below & why does this happen?

What I can't understand out of this error, is that I can't comprehend what @dart=2.9 is. I hadn't previously run or coded the file in a while. So, when I came back to work on this flutter file project, it threw me this error?

I tried updating flutter on the command prompt. Everything it's fine according to the flutter doctor. The only missing piece is just visual studio, but I use visual studio Code. So, I am assuming that's not the problem. If not, then what could it be? I am deeply thinking about this long error, that can't get to comprehend.

Much appreciation in advance any sort of help will be gratefully appreciated

Error: Flutter run - When I run flutter run it always displays the errors below.

Invalid depfile: C:\Users\14706\Desktop\Test-SETUP\New folder\This_Folder_Contains_Map_Tests_From_Top_To_Bottom_Atempts\Challenge_1\flutter_login_auth\.dart_tool\flutter_build\6494cc4bb6a11f1a583790c79662ece5\kernel_snapshot.d
Invalid depfile: C:\Users\14706\Desktop\Test-SETUP\New folder\This_Folder_Contains_Map_Tests_From_Top_To_Bottom_Atempts\Challenge_1\flutter_login_auth\.dart_tool\flutter_build\6494cc4bb6a11f1a583790c79662ece5\kernel_snapshot.d
../../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/firebase_database-6.1.2/lib/firebase_database.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
// @dart=2.9
^^^^^^^^^^^^
lib/Pages/auth/mainLoginCheck.dart:2:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^
../../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/firebase_database-6.1.2/lib/src/utils/push_id_generator.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
// @dart=2.9
^^^^^^^^^^^^
../../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/firebase_database-6.1.2/lib/src/database_reference.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
// @dart=2.9
^^^^^^^^^^^^
../../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/firebase_database-6.1.2/lib/src/event.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
// @dart=2.9
^^^^^^^^^^^^
../../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/firebase_database-6.1.2/lib/src/firebase_database.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
// @dart=2.9
^^^^^^^^^^^^
../../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/firebase_database-6.1.2/lib/src/query.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
// @dart=2.9
^^^^^^^^^^^^
../../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/firebase_database-6.1.2/lib/src/on_disconnect.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
// @dart=2.9
^^^^^^^^^^^^

Unhandled exception, umm...??? what even is this error that comes along down here?

Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:dart
%3Ahtml; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)
#1      asFileUri (package:vm/kernel_front_end.dart:659:37)
#2      writeDepfile (package:vm/kernel_front_end.dart:799:2
1)
<asynchronous suspension>
#3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:625:9)
<asynchronous suspension>
#4      starter
 (package:frontend_server/frontend_server.dart:1451:12)
<asynchronous suspension>
#5      main (file:///C:/b/s/w/ir/x/w/sdk/pkg/frontend_server
/bin/
frontend_server_starter.dart:10:14)
<asynchronous suspension>
FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\14706\Desktop\CODES\Flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1159

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\14706\Desktop\CODES\Flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 28s
Running Gradle task 'assembleDebug'...                             30.1s
Exception: Gradle task assembleDebug failed with exit code 1
Error: Not found: 'dart:html'
import 'dart:html';

I have previoulsy tried updating flutter on command prompt. Everything it's fine according to flutter doctor. I have tried looking on what @=dart=2.9 is? but not enought understanding still. I have also tried looking on something the error highlights which is 'dart:html'; still, I don't comprehend how and why that is an errors?


Solution

  • 1-just delete import 'dart:html'; from your code

    2-run flutter clean then flutter pub get

    if that doesn't work check this