Reputation: 51
I see that Flutter has conditional import statements, but after looking at some examples I’m still confused.
If I want to have main.dart import package “package:xyz/xyz.dart” only when the user is on web, how can I achieve that in the simplest way? Thanks for any tips.
Upvotes: 0
Views: 1839
Reputation: 4854
We could import a package only for the web users by the use of a conditional import:
import 'package:xyz/mobile.dart'
if (dart.library.html) 'package:xyz/web.dart';
The code above imports package:xyz/web.dart
only if dart.library.html
is available, which happens to be the case for the web platform.
Upvotes: 5