Here i will cover the steps, those are needed to convert a Flutter mobile to browser app. By this, I mean how to run a mobile app in the browser.
In general pretty much the below command could do the tricks.
flutter run -d chrome
The above command does the trick. But sometimes it is not that simple. For example, in my case I was running Firebase on my mobile app and this Firebase was causing problem.
Make sure you backup your file first.
There are at least three issues, that could hinder you running your app on web browser.
- Firebase files
- Platform dependant files
- Flutter channel
Below we check them one by one
Firebase files
So first I just wanted to run the app without firebase. So I deleted all the firebase files and commented out all the firebase related code.
If you face the same problem you need to make sure you comment out firebase related files.
See how I commented out the files.
Platform dependant files
Now if you use any platform dependant files, they may also cause issues as you run. I mean if you specified iOS and Android platform before, you will get the error like platform localName
I also commented those out.
This line was causing error. So I commented out that too. Otherwise you might the below error
Error: Unsupported operation: Platform._localeName
And then run the package command below to install a package called universal_io
flutter pub add universal_io
The above command would install a new package and would remove dart:io dependency issues. And this is how I replaced the dart:io package
See line 6, I have removed dart:io and add universal_io on line 7
Flutter Channel
In my case I had to change to Flutter master channel before I was able to run it. In general maybe you are on stable channel. Switch to master channel.
If you run the command flutter channel you will see the above output. So switch to master channel by running the command below flutter channel master
The above command may download a lot of files. Make sure you patient. While you are waiting check out complete Firebase free master class course