Why do I get white screen when building flutter web - flutter

I want to build a flutter web app, so I enter 'webdev build' command and after the operation finishes, I open the 'index.html' file located in build directory and it's just a white screen.
I tried it on a fresh project and the problem persists.
There's no problem during developing.
Here's my flutter doctor output:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 10.0.17134.766], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.3)
[√] VS Code (version 1.35.1)
[!] Connected device
! No devices available
! Doctor found issues in 1 category.

For me seemed to have been a problem with antivirus and running flutter run -d chrome --release solved my problem.

You need to run webdev serve command, it'll provide an address like localhost:8080 or 127.0.0.1:8080. I've attached a screenshot after running webdev serve for one of my Flutter Web Project. It says Serving web on http://127.0.0.1:8080 So you need to open that URL in Browser.
This answer was written when flutter-web was a separate project and webdev was the way to go for running your app.
Now you can use flutter run -d chrome to run it for Web.

You have to upload your files to the server and put them inside the root folder.
If you want to put them in other folder, you have to edit the "index.html" file to tell hem the folder.
For example:
If you upload your files to "test" folder, you have to edit this line of "index.html":
<base href="/">
To
<base href="/test/">

I had the same issue. I was in stable channel and doing below solve the issue:
flutter clean
flutter pub get
flutter pub cache repair
I hope solve your problem.

I had the same issue.I used inspect code on chrome and checked console section.So there was error not allowed to load local resource and a Path to some file was like this:
import 'file:///C:/Users/../someFile.dart';
And by changing path to
import 'package:.../someFile.dart'
white screen gone and problem solved.

I didn't pay attention to this part from the documentation,"run the application using a static HTTP server.". I was just opening the index.html not using it is server.

For me I was in master channel and doing below solve the issue:
flutter channel dev
flutter upgrade
flutter run -d chrome

just run flutter config --enable-web in your command line and close your editor and after run the app again

I had the same issue. I was in master channel and doing below solve the issue:
flutter clean
flutter pub get
flutter pub cache repair

I had the same problem with my app running as a blank page in Chrome. I've fixed it by re-creating a project with flutter create .:
move your lib directory and pubspec.yml file to a safe place.
then, delete the rest of the files and directories in your project directory.
run flutter create ..
move back in those files from step 1.

form me was to replace
<base href="$FLUTTER_BASE_HREF">
to
<base href="">
in index.html file

Related

error when i run flutter doctor --android-license

Good day Guys, i'm new on flutter & I wan set up flutter and the android SDK(without using android studio) on my device but when i run flutter doctor --android-licenses command i get this error after running the command
(/home/olaneat/android/Sdk/tools/bin/sdkmanager).
Try re-installing or updating your Android SDK,
visit https://flutter.dev/docs/get-started/install/linux#android-setup for
detailed instructions.
this is how i configured my path
ANDROID_HOME="$PATH:/home/olaneat/android/Sdk"
export PATH="$PATH:/home/olaneat/android/Sdk/platform-tools"
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
export PATH="$JAVA_HOME/bin:$ANDROID_HOME/cmdline-tools/tools/bin:$ANDROID_HOME/platform-tools:SPATH"
and i have my SDK already installed
can anyone help out?
Update cmdline-tools direcotry
Try changing the path name cmdline-tools/tools to cmdline-tools/latest. I was facing the same problem and found that the directory patern has been updated.

Can't load kernel binary:Invalid SDK hash

I want to run flutter web after write flutter channel beta it replies: Can't load kernel binary:Invalid SDK hash, do you know how to solve this problem?
locate flutter installation folder
delete flutter/bin/cache
-run flutter doctor

Could not find an option named "devtools-server-address". when trying to run flutter app from AndroidStudio

I just updated Flutter plugin to 53.0.1, restarted Android Studio and hit "run" button and the error below show up:
Could not find an option named "devtools-server-address".
Close and reopen AndroidStudio resolved for me!
killall java
I downgraded from Flutter 2.0 to Flutter 1.22.5 and got this error.
To solve it,
Go to your terminal and write flutter channel stable.
Then run flutter doctor.
Now you may get another error like this -
If you have Flutter & Dart plugins already install, just ignore this error. This is a bug in Flutter 1.22.5 .
Just run the app and it will work fine!
I had the same issue but using VS Code on stable channel
Execute the following commands:
flutter channel stable
flutter upgrade
flutter clean
flutter pub get
Then, close and open your IDE
Follow the steps:
File -> Invalidate Cache and Restart. Run flutter clean Worked For me.
This so simple... Open terminal type flutter channel dev this solve your problem.
And after that flutter upgrade
Finally, flutter doctor
If it does not help:
Open terminal type flutter channel stable
And after that flutter upgrade
Finally, flutter doctor
Working without upgrading flutter
Safe fix for Mac (Android Studio 4.1+). It is in a different directory now, but the symbolic link helps.
Just run this command in the Terminal:
ln -s ~/Library/Application\ Support/Google/AndroidStudio4.1/plugins ~/Library/Application\ Support/AndroidStudio4.1
Change the version of the Android studio depending on what you have, I had 4.2 so used.
ln -s ~/Library/Application\ Support/Google/AndroidStudio4.2/plugins ~/Library/Application\ Support/AndroidStudio4.2
Just Invalidate Cache and Restart. Worked for me.
Just close your all project and also close Android Studio and Reopen.

Why won't my Flutter web app debug open in the browser?

In VScode, I used to be able to go 'Run' -> 'Run without debugging' and if the 'Web server (web-javascript)' was chosen then the Flutter app would open in debug mode in Chrome. This used to open a new Chrome window for the app to be displayed in. I'm not sure what I've done but this no longer works. I now get the message below showing in the debug console. I have tried to go to the localhost link in Chrome but I just get a blank screen and no errors in the Chrome console. I've tried downloading the Dart extension in Chrome but this doesn't help.
Launching lib\main.dart on Web Server in debug mode...
Waiting for connection from Dart debug extension at http://localhost:51367
So far I have tried reinstalling VScode and Flutter, reinstalling the Dart and Flutter extensions. I've even tried to uninstall VScode and remove all the extension and settings files that get left behind (like mentioned here). I've set Flutter up as the Flutter website says every time but none of this has helped and I have no idea what has gone wrong. Could anyone help?
In case it helps, here is the Flutter doctor output:
Downloading android-arm-profile/windows-x64 tools... 1.7s
Downloading android-arm-release/windows-x64 tools... 0.8s
Downloading android-arm64-profile/windows-x64 tools... 1.2s
Downloading android-arm64-release/windows-x64 tools... 1.3s
Downloading android-x64-profile/windows-x64 tools... 2.2s
Downloading android-x64-release/windows-x64 tools... 1.0s
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, 1.20.0-7.3.pre, on Microsoft Windows [Version 10.0.18362.959], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.0)
[√] VS Code (version 1.47.3)
[√] Connected device (2 available)
• No issues found!
The problem for me was in the index.html file located in the "web" folder.
The cause for the error was my <script src="main.dart.js" type="application/javascript"></script> line. It was not at the very bottom of the body tag. Moving it to the bottom fixed the issue.
You might also need to re-check the index.html file in general. The general order inside the body tag should be as follows:
1-
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('flutter-first-frame', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
2- (applies to firebase users) Firebase CDN scripts. ex:
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
3- (Firebase users)
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "<your api key>",
authDomain: "<your auth domain>",
projectId: "<Your project id>",
messagingSenderId: "<your messaging sender id>",
appId: "<your app id>"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
4- (most importantly) Make sure this line is at the bottom of the body tag
<script src="main.dart.js" type="application/javascript"></script>
I had to rerun flutter config --enable-web after an upgrade to get it working again. Then restart vscode and run.
For me. All I had to do was to make sure that Chrome was the default browser.
if you want to run your flutter web code in a specific port or..., you will see this error.
The web-server device requires the Dart Debug Chrome extension for debugging. Consider using the Chrome or Edge devices for an improved development workflow.
Please click the Dart Debug extension button in the spawned browser window
you can easily install dart extension from dart-extention and click on it every time you run your code.
Last resort (maybe someone has a better solution). Make a new project and copy the lib across. Add anything needed in the pubspec.yaml
Simply open a new tab with the flutter app URL.
For me, I used an old project that has Android build files. I did the following
flutter config --enable-web
flutter clean
restarting vscode
It solved the problem.
I solved it after upgrading flutter to 3.0v.
flutter upgrade
Just in case anyone has facing this issue in vscode devcontainer, I had a hard time trying to figure out what was happening, I tried everything, flutter clean, forwarding port in devcontainer. It just happened that the version of flutter that i was using had the issue. I was using 3.6 and change to 3.9, everything is working right now.
I was getting a white blank screen and debug console said this
Running "flutter pub get" in flutter_application_1...
Launching lib/main.dart on Web Server in debug mode...
lib/main.dart:1
Waiting for connection from Dart debug extension at http://localhost:42207
The web-server device requires the Dart Debug Chrome extension for debugging. Consider using the Chrome or Edge devices for an improved development workflow.
Please click the Dart Debug extension button in the spawned browser window
flutter run -d web-server in cmd line worked for me though I have to press 'r' manually to reload
If running on the web check the web console. I had a js function that double declared "index".

Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds

Log:
E:\Flutter>flutter doctor Checking Dart SDK version... Downloading
Dart SDK from Flutter engine ead227f a... Unzipping Dart SDK...
Updating flutter tool... Error: Unable to 'pub upgrade' flutter tool.
Retrying in five seconds...
Waiting for 0 seconds, press CTRL+C to quit ... Error: Unable to 'pub
upgrade' flutter tool. Retrying in five seconds...
Waiting for 0 seconds, press CTRL+C to quit ... Error: Unable to 'pub
upgrade' flutter tool. Retrying in five seconds...
Waiting for 0 seconds, press CTRL+C to quit ... Error: Unable to 'pub
upgrade' flutter tool. Retrying in five seconds...
Waiting for 0 seconds, press CTRL+C to quit ... Error: Unable to 'pub
upgrade' flutter tool. Retrying in five seconds...
Waiting for 0 seconds, press CTRL+C to quit ... Error: Unable to 'pub
upgrade' flutter tool. Retrying in five seconds...
First Make sure you have a working internet connection and if this issue still exists then, this error may be because the dart sdk may have not been properly downloaded.
The simplest solution is to delete the cache folder located in
flutter/bin(location where flutter is installed) and then Run flutter doctor
I fix that by:
Ctrl+C to stop infinite error loop.
Kill the Dart process in Windows Task Manager.
Delete the cache folder located in flutter/bin directory.
Run in command line flutter pub cache repair.
After that I run flutter doctor and get predictable results:
e:\tools>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version
6.1.7601], locale ru-RU)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.6)
[!] IntelliJ IDEA Community Edition (version 2019.2)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Ultimate Edition (version 2019.2)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[√] VS Code (version 1.44.2)
[√] Connected device (1 available)
! Doctor found issues in 2 categories.
I found my antivirus blocks pub upgrade,I had same issue while hitting flutter doctor, I turned off my antivirus and tried to run "flutter doctor" again, and worked well!
windows:
simplest and easiest way is download the latest version flutter sdk. replace manually current folder by pasting downloaded flutter folder instead of the current folder
in c drive. always choose replace and paste.
after finishing that check with flutter doctor. my issue solved
Solved this issue when Run the CMD as administrative.
This issue will come in protected network as well as due to anti-virus. Even I was facing the same. I downloaded latest stable version manually from the following link, which doesn't required any update process and it works for now..
Download Link For Flutter in Zip format
I updated the flutter SDK via git pull, then the flutter doctor command works.
Just delete the cache folder in flutter/bin and run flutter doctor again!!
Just Deactivate your antivirus and run it again. It would work fine. I had the same issue before.
I deactivated my antivirus for some time and executed flutter doctor command once again in cmd and got fruitful results after hours of patience.
One more thing to note, you should ensure that path of dart-sdk folder should be added to the path in user variables.
It seems it is not being able to "unzip" the downloaded Dart file because it misses 7-zip uncompressor.
I installed it and it worked! It will deal with .7z files.
I hope it works for other people too!!
I had the same problem and it was solved.
Steps:
Download Dart and Filters SDK then Decompress these files and move them to this directory.
C: \
Define the variables in path:
Delete cache directory in flutter/bin
Then run flutter doctor
Make sure you downloaded the windows powershell i use windows 8 it wasn't installed by default , when i downloaded it it worked for me.
Check your flutter bin path in environment variable(User Variables). If not go to Under User variables check if there is an entry called Path:in that add this flutter/bin path.
Strangly when I kill the dart process in Windows Task Manager it is working. But sometimes even when dart process is running update working.
I had to turn off the Android Emulator. It was running for me...
I got the same error and was not able to get rid of it. So I deleted the flutter and instead of cloning it I downloaded the zip from the flutter website and extracted it. Now it works just fine.
Manually downloading the SDK from flutter website fixed the issue.
Still dont know why this problem occured tho.
If you are using Avast (or possibly some other anti virus too) on Mac and have recently updated the OS to Big Sur then follow the below steps to fix this issue
Open Avast and in the Web Shield area disable the "Scan secure connection".
Run flutter config --no-analytics and then run pub upgrade.
This should probably fix the issue.
You can also refer to below threads in Github for more details about the cause
https://github.com/flutter/flutter/issues/40515
https://github.com/flutter/flutter/issues/68999
In my case, the error resolve after adding below folder into exclude option in anti virus
Flutter SDK location
D:\Android\flutter_windows\flutter\*.
Flutter Local Pub folder
C:\Users\hitesh\AppData\Local\Pub
You get the error --
"Pub failed to delete entry because it was in use by another process.
This may be caused by a virus scanner or having a file
in the directory open in another application.
Error (1): Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (1 tries left)" even if you are in one of the flutter directories from Windows explorer. Close the window and try running Flutter doctor. This will resolve.
If anyone faces this problem on macOS with AdGuard installed. Try this:
Go AdGuard Preferences -> Network -> Automatically filter applications -> Select Mode... and change mode to Automatic Proxy.
Pub failed to delete entry because it was in use by another process.
This may be caused by a virus scanner or having a file
in the directory open in another application.
Error (1): Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
Tried switch to Dev channel and got stuck with "Unable to pub upgrade". Did everything and nothing worked.
This is what I did:
Renamed the Flutter SDK folder
Download the latest Flutter SDK
Extract to the same location of previous renamed SDK
Flutter channel Dev
Flutter upgrade
And everything back to normal.
Source of Problem
It might be possible that you don't have enough free disk space. That's what caused my problems to begin with.
Solution
In my case,
First I had to clean up space to remove any unused files.
Then I had to overwrite the flutter SDK folder due to corruption. The SDK can be found here.
I had the same issue with my MacBook M1. I tried deleting and running flutter pub cache repair But It didn't work for me.
Then I ran the command softwareupdate --install-rosetta and accepted the software licences & agreement (After installing XCode). Now the command flutter works fine. :)
Tried all of the above without success. The search order in the PATH system variable turned out to be the problem:
it was:
G:\My Drive\Compilers\flutter\bin;
G:\My Drive\Compilers\flutter\bin\flutter;
G:\My Drive\Compilers\flutter\bin\flutter.bat;
G:\My Drive\Compilers\flutter\bin\dart.exe;
G:\My Drive\Compilers\flutter\bin\dart;
G:\My Drive\Compilers\flutter\bin\dart.bat;
changed it to:
G:\My Drive\Compilers\flutter\bin\flutter
G:\My Drive\Compilers\flutter\bin\flutter.bat
G:\My Drive\Compilers\flutter\bin\dart
G:\My Drive\Compilers\flutter\bin\dart.bat
that fixed it
Mac auto iCloud upload might be causing the error
If you are using Mac and if your Desktop files are being uploaded to iCloud automatically, sometimes iCloud uploads the "bin" file or the "cache" file inside the flutter file. I've just downloaded the file onto desktop (right click the file -> "Download Now") and it downloaded the file, it ran as usual. (Automatic upload can be turned off from system preferences if youn are getting this error frequently like I was).
For my case, i was using ubuntu, and after reading the above comments, i have come to a resolution that the above error comes as a result of permissions being blocked, accessing cmd with admin access levels solves the problem, e.g on linux run sudo flutter doctor and the problem will be solved.
This error occured to me when i tried upgrading my flutter so it needed admin rights to be upgraded nothing much