How to develop for multiple platforms in flutter when some packages are not compatible with some platforms?

Viewed 333

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.

1 Answers

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