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
3
Answers
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:
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: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 thepubspec.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
To make it work for a dev build, I incorporated Spanching’s answer above in the following steps.
flutter clean
to clean up all build cache (this is important to have canvas kit re-downloaded in step 4 below).flutter pub get
to download packages per pubspec.yamldart 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)flutter build web
At this stage you should have a clean
/build/web
added with acanvaskit
folder underneath it. Full path:/build/web/canvaskit/
Then:
index.html
under/web
(note – do not open the one under/build/web
)