1

I want to use a plugin on my flutter app, but since it doesn't works as spected on Android but it does on Ios, I want to use it only on Ios for a while. Is there a way to import a package only for Ios platform?

  • not works means the plugin works but not works as desired? there is no build issues etc? – Dev Jun 12 '23 at 12:38
  • Exactly, no build issues or anything. I need the plugin to not be imported on Android since it uses permission that I can't declare because i'm not using that plugin functionality – Alvaro Dosio Jun 12 '23 at 12:41

1 Answers1

0

You can totally use specific platform code with imports as well.

Remember to add the necessary dependencies to your pubspec.yaml file for the iOS-specific package you want to import.

import 'package:flutter/material.dart';
import 'dart:io' show Platform;

void main() {
  // Common code for all platforms
  
  if (Platform.isIOS) {
    // Import and use iOS-specific package
    import 'package:your_package/ios_specific.dart';
    
    // Use the iOS-specific package
    iOSPackage.doSomething();
  }
  
  // Rest of the code
}
Colin Lazarini
  • 754
  • 4
  • 14
  • I did it, but importing the package made my AndroidManifest.xml to declare a couple of permissions that I won't need on Android. – Alvaro Dosio Jun 14 '23 at 10:29