Is is possible to build flutter web in release mode? The only commmand I found to run on web was either :
flutter run -d chrome
but it's in debug
or I use :
flutter run -d web-server --web-port 5000 --web-hostname localhost
to run a local webserver to avoid having to use a new chrome everytime I debug anything.
My problem is the following and pretty simple : I have code that crashes in release mode when webApp is built and deployed on github pages, but the stack is impossible to understand, also this very code doesn't crash when I test it in debug mode ( again the error stack looks like this ):
main.dart.js:4315 Uncaught TypeError: n.gawc is not a function
at main.dart.js:22638:13
at aAA.a (main.dart.js:5512:62)
at aAA.$2 (main.dart.js:39196:14)
at Object.E (main.dart.js:5498:10)
at Object.QE (main.dart.js:22648:10)
the javascript is obfuscated so I don't know at which point it's hapenning, and if I want to test anything I need to build for web and upload on github pages, then wait 1 hour for it to be live to be able to see my prints in the console which are placed completely blind.
Is it possible to build for web in release mode locally?
Thank you for your time.
Your question asks about building for web in release mode. So the following does that for you.
flutter build web --release
To actually run a local release version. You just need.
flutter run --release
See this for more info https://docs.flutter.dev/testing/build-modes
Related
I created a flutter web application,
and I finished building it with the command ..
flutter build web --release ,
and then transferred it to a local server ,
The site does not work unless it is connected to the Internet ,
I want the site to work without an internet connection ,
As I work in an organization and some users do not have internet permissions .
Please, I want a solution to this problem .
Thanks
The problem is, that flutter has some dependencies, that can not be resolved when you, as the client, are offline. Mostly consisting of canvaskit and certain google fonts.
There are multiple solutions for that. The easiest being to use the html web-renderer:
flutter build web --release --web-renderer html
this should work for most applications, however it has lower performance than canvaskit, especially with high widget density.
Therefore you can also use canvaskit locally as it is automatically built when you build your release. But you have to set it as base url, by adding the following lines in your index.html:
<script>
window.flutterConfiguration = {
canvasKitBaseUrl: "/canvaskit/"
};
</script>
This makes sure your flutter application uses the local source for canvaskit. However, another problem could be the usage of google fonts, e.g. Roboto, as those often need to be downloaded as well. But you can just add those to the pubspec.yaml explicitly to account for that, like explained here.
Some sources for more informations:
flutter web-renderers
The same issue but on github
Making Flutter offline capable
Download and set locally from asset policy for your web application
Add link to local Canvaskit as bellow :
flutter build web --web-renderer=canvaskit
--dart-define=FLUTTER_WEB_CANVASKIT_URL=/canvaskit/
To make it work for a dev build, I incorporated Spanching's answer above in the following steps.
Run: flutter clean to clean up all build cache (this is important to have canvas kit re-downloaded in step 4 below).
Run: flutter pub get to download packages per pubspec.yaml
If you're using build runner: dart run build_runner build --delete-conflicting-outputs
At this stage you should have a clean /build folder (I also have an ios sub-folder as I'm also developing for iOS)
Run: flutter build web
At this stage you should have a clean /build/web added with a canvaskit folder underneath it. Full path: /build/web/canvaskit/
Then:
Open index.html under /web (note - do not open the one under /build/web)
Add the script mentioned in the answer above to the body of the html file. I just added it above the existing script that's already there.
Run your project in deubg mode (with Wifi turned off).
I'm doing some tests with web_socket_channel Flutter plugin and I've noticed a very strange behavior. I've implemented flutter-dev's example, just changing the socket kind to HtmlWebSocketChannel in order to make it work in web builds. If I compile my app with flutter build web --release and later I expose it with a local webserver, it works perfectly fine. Same happens if I execute it in debug mode.
add network permission in mainfest.xml
I'm trying to run my first flutter code on the web. I followed setup instructions provided in Building a web application with Flutter and created a very simple app, that's only supposed to display a navigation bar. Now as I'm running my application for the first time on "Chrome (web)" device, it won't connect to the browser. It's been almost 20 minutes and it's still telling me "Attempting to connect to browser instance".
> flutter run -d chrome
Launching lib\main.dart on Chrome in debug mode...
Building application for the web... 1215.1s
Attempting to connect to browser instance..
(This is taking an unexpectedly long time.)
Can anyone guide me on how to fix this?
In my case, I couldn't disable the virus guard. So I used the server mode.
flutter run -d web-server
Launching lib\main.dart on Web Server in debug mode...
Building application for the web... 8.8s
lib\main.dart is being served at http://localhost:57598/
Then go to the URL shown.
The same thing happened to me, I disabled the anti virus and it worked
It's mostly nothing to do with Flutter but, it's either because you have logged in your computer in safe mode. In my case the shift key was stuck and I had no idea I was in safe mode.
Or else You need to check your firewall, go to System Preferences > Security and Privacy > Firewall --click the lock below and enter your system password -- and then click firewall option -- In there add your editor to allow internet connection for android studio Or VS Code.
I experienced the something similar, chrome opens but never showed the web app (just white screen). In my case it had to do with the interaction of flutter and riverpod.
If you are using riverpod 1.0.0 and flutter 2.5.3 you need to update flutter to 2.8.0 or 2.8.1 (see this issue: https://github.com/rrousselGit/river_pod/issues/889)
I should have bookmarked it, but the googles aren't being helpful.
There was a recent (past week or so) that the standard flutter command on the master branch can now eliminate the difference between Flutter and flutter_web repositories. This will be helpful for an upcoming demo.
Since the question is asking where the announcement link was, I bookmarked them. (Probably you don't need anymore though).
https://groups.google.com/forum/#!topic/flutter-announce/-LQPz3C3JAM
https://www.reddit.com/r/FlutterDev/comments/cl6cul/flutter_for_web_preview/
Edited:
I just tried the new approach and made some mistakes. So I would like to share more on this.
Steps at Flutter (Channel master, v1.9.1-pre.91):
First create a new project:
flutter create --web project
OR
$ flutter create project
$ cd project
$ flutter create --web .
Compile and Run the project with chrome (will launch chrome)
$ flutter run
That's all.
Another thing I found out: if you add the plugin which flutter web does not support, you can still pub get, compile successfully. The error will only happen when the unsupported code is triggered and then report some exceptions such as NoSuchMethodError: '<Unexpected Null Value>'.
Another Note: If you don't connect any mobile devices, flutter run by default will launch the chrome device. If you connect a mobile device, flutter run will pick the mobile device, compile and install it to your mobile device (at least it's the case in my env). So when you have both mobile and chrome devices, to launch the web case, simply execute flutter run -d chrome.
More links:
https://github.com/flutter/flutter/issues/34082
https://github.com/flutter/flutter/wiki/Building-a-web-application-with-Flutter
my ionic project works fine with ionic serve --lab ,but while copied the.apk file in build folder to my phone and install the app but blank screen appears ,
Please can anyone suggest what might be my problem
my app is using google maps,key is provieded for both app and browser in index.html
Have you tried running it in the emulator ? Since its much easier to see the error logs . Try ionic emulate android -l or ios -l (whichever OS you are building for) and then once the execution starts run the command consolelogs it will log all the activity and you will have a better understanding about why its not working.
+1 for using Chrome Remote Debugging feature. It give you the same output as you would receive from running you app in the browser.
Additionally, I have found that sometimes if your app is already compiled, the ionic CLI doesnt always copy your current files into the APK, and uses the older cached files instead. If you are banging your head against the wall, run the following commands to make sure you have your latest code in your APK.
ionic platform remove android
ionic platform add android
ionic run android
I suggest you use the Chrome Remote Debugging feature. I encountered the same, and looked for answers to my symptom for hours. Once I connected to the chrome remote debugger, I got the console.log back, and noticed there was a problem in my routing setup.
It was a problem with ionic CLI. I've updated it to the latest and reinstalled all dependencies.