Home > Enterprise >  Is there a way to run a flutter app on web when the app uses a plugin which is not developed for web
Is there a way to run a flutter app on web when the app uses a plugin which is not developed for web

Time:11-16

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.

CodePudding user response:

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
}
  • Related