Flutter websocket working in local web but not in release mode - flutter

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

Related

Flutter build web in release mode

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

How can I run flutter web app without internet connection

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).

How to use proxy in Wi-fi setting for the app in Flutter app?

Case:
I use Flutter to create an app, and the app will call Restful Api to backend server to get data.
However, the backend server only open to a selected host and port for security reason.
The app works well if it is under that network, but cannot works properly because of fail to get data if out of that network.
As a result, I would like to setup a proxy for the wi-fi I'm using, and run the app as normal.
Unfortunately, the flutter app still not working in both Android and IOS platform.
Question:
How to use proxy in Wi-fi setting for the app in Flutter app?
You may try using this package to apply the system's global proxy settings: https://pub.dev/packages/native_flutter_proxy
Dart's networking tools don't pick up these settings on their own.

Flutter: wasm streaming compile failed: TypeError: Could not download wasm module

I'm building a Flutter web app. Everything was working fine until randomly I did a hot restart and then I began getting this error.
wasm streaming compile failed: TypeError: Could not download wasm module
Tried 2 things
Reverted the code back to a known working state (from git source control) and I still get this error.
Created NEW Flutter project from Android studio using New Flutter project options. Still did not work.
Any ideas? I tried to update Chrome and this did not help.
I lived in a remote area where no broadband is available so I use wireless network through sim card. The operator network is disturbing ,I can browse website sometimes and some times bit laggy on the other hand my flutter project work on emulator but I can not run it web. I changed the operator network and get a good quality of internet connection than The issue gone. What I think some module in web need to build good internet connection. I don't know this answer is helpful or not but this is how I solve my issue
It needs a stable internet connection to run. The error gone once I switched to good internet.

possible way to run actual application

I am making a testing scenarios using Ogurets framework which is cucumber + gherking combination.
The tests are for Flutter application written in Dart language.
I recently figured out that test driver does not execute actual app. For example in my case:
I have and app where is a Login feature. After navigating to Logout and clicking on it, app does not return the login screen(it does back-end work though), but when I execute actual app through main.dart file and not using Ogurets configuration everything works as expected.
So I was wondering,
Is there any possible way to execute actual app during testing scenario? Lets say It can execute release version of the app.
Not sure if it makes sense.
Thx for possible tips
So when Ogurets runs, it will execute a command to "flutter run" your application, and using the standard mechanism for Flutter Driver, it will create a tcp link between your running application and the Ogurets code. But to do this, you have to have the extra Flutter Driver code enabled in your application, so it is not possible to run your "actual app", otherwise this TCP link will not form.
Over this TCP link standard Flutter Driver commands are executed and you can also execute extra commands. So your actual app is being executed as if you are running it using "flutter run" - and you can even run it on a real device this way, but it can never be your released application as it will not have this extra TCP link code.
If you are having trouble understanding why your application is operating like this, the documentation for Ogurets Flutter does indicate how you can run and debug the two sides of the application, so you can be running your Flutter App in debug mode and then run your tests, have it connect and automate the app and then debug why it isn't coming back to your login page. This is what I would recommend you do.