I have developed a web app using Flutter in Android Studio IDE, and have enabled Flutter Web from the Flutter console. In Android Studio, I am able to run the app and use Chrome(web) as my target device; and the app runs well.
Can anyone advice what is the next step to export this to a web hosting service? Like PorkBun. Any help is appreciated, thanks!
Run this command in the terminal:
flutter build web
It will compile your project for the web, then you should see a generated files under [your_project]/build/web
Upload the contents of the web folder to the root folder of your hosting service. The main page index.html should run your app.
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 make flutter web app and test in debug mode. That is working. Later, Run flutter build web --release this command and then copy files from build/web to the web folder and host on github pages. All is work.
later, I fix some functions and do that above steps again, but nothing changes in github pages. Always show old web, functions. But there is changes in web debug mode. I build with flutter 2.0. How to fix that problem or how should I do?
Do flutter clean. Build for web again and upload the latest build files. Probably your ide created a build from cache
I can solve now...
1.
Clean the build file or type the command flutter clean
2.
Build web release with flutter build web --web-renderer canvaskit --release
3.
Copy all of files and folder inside from web folder inside build folder build/web , to the repo and push again.
I have added flutter web support in my existing flutter application. Successfully run in chrome browser using flutter run -d chrome. Then i have created a build for a web using flutter build web. How can i deploy or host this build to the URL for testing in any other browser.
My build we folder is looking like this...
I want to know that if it is possible to make flutter app for web without using HTML, css or javascript and only using flutter and dart
Yes, it is absolutely possible to create a web app using flutter and dart.
To add web support in the existing flutter project you can run the command flutter create . and to release it run the command flutter build web
For testing your app in chrome you can use command flutter run -d chrome
You can disable android support using command flutter config --no-enable-android and disable ios support using command flutter config --no-enable-ios
Yeah, it is not need to build web app with HTML,CSS & JS, your flutter code alone will work.
Note: try flutter upgrade bcs v-2.0.0 stable release for web got released
Yes, you can use Dart/Flutter exclusively to build web apps. You don't need to write any HTML/CSS/Javascript.
You can setup your project from the terminal (like previous comments suggests), or you can use an IDE such Android Studio, or you can use Visual Studio.
If you use Android Studio, you can create a new Flutter Project, and select the 'web' platform only, and de-select Android and IOS.
I am currently using Dart/Flutter to build web apps only. Android Studio builds the HTML/CSS/Javascript for you. Then you just have to publish it into a web server (online or local).
Yes you can use Flutter for web apps but though it is in early stage of development about how the web app will be stable or not
I've just created a flutter web application and now I am ready to deploy it. Looking at the docs it looks like I need to use Firebase Hosting? But I want to host the app on my own server. I tried copying the web directory from Build but when I go to the path I get a blank screen on web. How do I deploy it correctly? Or is it just simply not possible without Firebase?
First you need to compile the application.
In a terminal, command prompt or Powershell, go to the root directory of your project.
From there run a build:
flutter build web
This will create a new directory inside your project.
c:\your-project-folder\build\web
Copy everything that is in the web folder to wherever you want to publish / host your application.
Your application is bundled up into a main.dart.js file.
An index.html is also in that directory. You should be able to run your Flutter web app by visiting that index.html.
All the instructions for building a Flutter application for web platform is here.