injectable icon indicating copy to clipboard operation
injectable copied to clipboard

Is it possible to make web only injection?

Open mirkancal opened this issue 3 years ago • 1 comments

I've separated the environments by web and mobile. Both my WebDownloader and MobileDownloader are registered as ImageDownloader(abstract class). But since WebDownloader's file has dart:js and dart:html imports, app throws:

Error: Not found: 'dart:html' errors

Is there any other way to make generated file doesn't import the file with web imports at all?

mirkancal avatar Jun 06 '22 14:06 mirkancal

This has to be done compile time, you have 2 ways (afaik):

  1. use conditional import, explained for example here
  2. create plugin, you will have a package for each platform you want to support with the platform specific code (can also be Dart only) and then one main package with the abstract interface. Compiler will then use the correct platform package.

First way is simpler for things like single class, but I think you will have to name those classes the same (you cannot have one named Mobile and the other Web I believe). With the second way wou'll have much more flexibility, but might be overkill for your need.

leoshusar avatar Jun 07 '22 06:06 leoshusar

use https://pub.dev/packages/universal_html?

mkysel avatar Nov 12 '22 14:11 mkysel

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

github-actions[bot] avatar Mar 24 '23 08:03 github-actions[bot]