Leveraging Apple's System APIs and Frameworks
When you come from iOS development, you might need to find
Flutter plugins that offer the same abilities as Apple’s system
libraries. This might include accessing device hardware or interacting
with specific frameworks like HealthKit
or MapKit
.
For an overview of how the SwiftUI framework compares to Flutter, see Flutter for SwiftUI developers.
Introducing Flutter plugins
Dart calls libraries that contain platform-specific code plugins. When developing an app with Flutter, you use plugins to interact with system libraries.
In your Dart code, you use the plugin’s Dart API to call the native code from the system library being used. This means that you can write the code to call the Dart API. The API then makes it work for all platforms that the plugin supports.
To learn more about plugins, see Using packages. Though this page links to some popular plugins, you can find thousands more, along with examples, on pub.dev. The following table does not endorse any particular plugin. If you can’t find a package that meets your need, you can create your own or use platform channels directly in your project. To learn more, see Writing platform-specific code.
Adding a plugin to your project
To use an Apple framework within your native project, import it into your Swift or Objective-C file.
To add a Flutter plugin, run flutter pub add package_name
from the root of your project.
This adds the dependency to your pubspec.yaml
file.
After you add the dependency, add an import
statement for the package
in your Dart file.
You might need to change app settings or initialization logic. If that’s needed, the package’s “Readme” page on pub.dev should provide details.
Flutter Plugins and Apple Frameworks
Use Case | Apple Framework or Class | Flutter Plugin |
---|---|---|
Access the photo library |
|
|
Access the camera |
|
|
Use advanced camera features |
|
|
Offer In-app purchases |
|
|
Process payments |
|
|
Send push notifications |
|
|
Access GPS coordinates |
|
|
Access sensor data4 |
|
|
Embed maps |
|
|
Make network requests |
|
|
Store key-values |
|
|
Persist to a database |
|
|
Access health data |
|
|
Use machine learning |
|
|
Recognize text |
|
|
Recognize speech |
|
|
Use augmented reality |
|
|
Access weather data |
|
|
Access and manage contacts |
|
|
Expose quick actions on the home screen |
|
-
Supports both Google Play Store on Android and Apple App Store on iOS. ↩
-
Adds Google Pay payments on Android and Apple Pay payments on iOS. ↩
-
Uses Firebase Cloud Messaging and integrates with APNs. ↩
-
Includes sensors like accelerometer, gyroscope, etc. ↩
-
Uses Google’s ML Kit and supports various features like text recognition, face detection, image labeling, landmark recognition, and barcode scanning. You can also create a custom model with Firebase. To learn more, see Use a custom TensorFlow Lite model with Flutter. ↩ ↩2
-
Uses the OpenWeatherMap API. Other packages exist that can pull from different weather APIs. ↩