5

I am trying to migrate my existing Flutter app to web. The problem is that certain packages are not compatible with Web, (e.g. path_provider and many others).

I don’t really want to build a whole new project so is there a way to exclude certain dependencies for web? Couldn’t find anything on this.

ouzari
  • 397
  • 3
  • 12
  • I am facing the same issue. I am tying to use https://pub.dev/packages/meta_seo for web, but I can't build for Android since it is incompatible. Did you find any answer? – Guillem Poy Dec 18 '22 at 12:50

1 Answers1

3

Yes, you can write platform specific codes, if you flutter app is meant to run on more two platform you need to use some packages for only one platform. This can also be done for all Platforms.

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

if (kIsWeb) {
// Use packages that are compatible with Web.
 } else {
 // Use packages that aren't compatible with Web.
}
david okoroafor
  • 313
  • 1
  • 7
  • 2
    Thank you. The problem is, I can't even build the project for web because of these incompatible packages. I want some way (if possible) to dynamically ignore (ie not include) them in pubspec.yaml when building for web ? – ouzari Nov 14 '21 at 12:12
  • ignoring or not including some packages in pubspec.yaml when building for web is not possible. Whether packages in pubspec.yaml are compatible with web or not, web will run perfectly until you use the package. @ouzari – david okoroafor Nov 14 '21 at 20:58
  • I have the opposite problem. I have packages for web only or mobile only separated by kIsWeb, like js, html, path_provider but I can't build for linux – markhorrocks Sep 12 '22 at 09:10