Flutter conditionnal import mobile vs desktop
249
There is no way to do what you are describing; conditional imports only support library-based conditions, and there is no difference in supported libraries for mobile and desktop.
Author by
Lulupointu
Updated on December 28, 2022Comments
-
Lulupointu over 1 year
Importing on web vs native is easy
import '../wrappers/platform/platform_none.dart' if (dart.library.io) '../wrappers/platform/platform_io.dart' if (dart.library.js) '../wrappers/platform/platform_web.dart';
What if I want to import a different package depending on whether I am on mobile (iOS/Android) vs on desktop (Linux/MacOS/Windows)?
If there is no way with conditional import, how can you achieve that any other way?
-
Lulupointu about 3 yearsTheorically the dart team could create dummy libraries that would serve this purpose then.
-
Lulupointu over 2 yearsAnyway sorry for not accepting earlier after much research you are right it cannot be done with the shipped libraries. I still think it's a pain but anyway ;)
-
Valentin Vignal over 2 years@Lulupointu have you found a workaround to this?
-
Lulupointu over 2 years@ValentinVignal As I said in one of the comment, one solution for me (having only an Android version of the plugin) was to create a dummy version of the class I needed manually (which only returns error) and then use conditional import. That's not the best but at least it work if you really need to, no matter how tedious