Interacting with hardware, third party services, and the platform
How do I interact with the platform, and with platform native code?
Flutter doesn’t run code directly on the underlying platform; rather, the Dart code that makes up a Flutter app is run natively on the device, “sidestepping” the SDK provided by the platform. That means, for example, when you perform a network request in Dart, it runs directly in the Dart context. You don’t use the Android or iOS APIs you normally take advantage of when writing native apps. Your Flutter app is still hosted in a native app’s ViewController
or Activity
as a view, but you don’t have direct access to this, or the native framework.
This doesn’t mean Flutter apps can’t interact with those native APIs, or with any native code you have. Flutter provides platform channels that communicate and exchange data with the ViewController
or Activity
that hosts your Flutter view. Platform channels are essentially an asynchronous messaging mechanism that bridges the Dart code with the host ViewController
or Activity
and the iOS or Android framework it runs on. You can use platform channels to execute a method on the native side, or to retrieve some data from the device’s sensors, for example.
In addition to directly using platform channels, you can use a variety of pre-made plugins that encapsulate the native and Dart code for a specific goal. For example, you can use a plugin to access the camera roll and the device camera directly from Flutter, without having to write your own integration. Plugins are found on pub.dev, Dart and Flutter’s open source package repository. Some packages might support native integrations on iOS, or Android, or both.
If you can’t find a plugin on Pub that fits your needs, you can write your own, and publish it on Pub.
How do I access the GPS sensor?
Use the geolocator
community plugin.
How do I access the camera?
The image_picker
plugin is popular for accessing the camera.
How do I log in with Facebook?
To log in with Facebook, use the flutter_facebook_login
community plugin.
How do I use Firebase features?
Most Firebase functions are covered by first party plugins. These plugins are first-party integrations, maintained by the Flutter team:
-
firebase_admob
for Firebase AdMob -
firebase_analytics
for Firebase Analytics -
firebase_auth
for Firebase Auth -
firebase_database
for Firebase RTDB -
firebase_storage
for Firebase Cloud Storage -
firebase_messaging
for Firebase Messaging (FCM) -
flutter_firebase_ui
for quick Firebase Auth integrations (Facebook, Google, Twitter and email) -
cloud_firestore
for Firebase Cloud Firestore
You can also find some third-party Firebase plugins on Pub that cover areas not directly covered by the first-party plugins.
How do I build my own custom native integrations?
If there is platform-specific functionality that Flutter or its community plugins are missing, you can build your own following the developing packages and plugins page.
Flutter’s plugin architecture, in a nutshell, is much like using an Event bus in Android: you fire off a message and let the receiver process and emit a result back to you. In this case, the receiver is code running on the native side on Android or iOS.