Ad

Is There A Way To Run A Flutter App On Web When The App Uses A Plugin Which Is Not Developed For Web

I am using firebase_dynamic_links in my app and I wish to deploy the app on the web. firebase_dynamic_links is not implemented for flutter web.

Now, I am using dynamic links in just one file. is it possible for me to use a separate code file just for the web version that does not use dynamic links?

The code is pretty extensive and the part consisting of dynamic links is pretty small, I don't want to maintain a separate repo just because of this.

Ad

Answer

You could simply wrap it in:

 try{
// app code
}catch(e){
// web code
}

You could also try:

import 'dart:io';

if(Platform.isAndroid){
// app code
}
else{
// web code
}

Although I've found that this will sometimes throw an error on the web, so you might want to wrap it it a try/catch.

You could also do:

import 'package:flutter/foundation.dart' show kIsWeb;

if (kIsWeb){
\\ web code
}
else{
\\ app code
}
Ad
source: stackoverflow.com
Ad