An example of Flutter Platform View plugin that works as a camera preview and capture.
Android | iOS | macOS |
---|---|---|
This sample has been presented during Flutter Vikings 2022 conference in Oslo.
If you'd like to learn more about Flutter, feel free to follow me here.
Make sure to use a recent master
version of Flutter (e.g. 3.5.0-10.0.pre.36
).
I recommend opening the whole workspace in VS Code by calling:
code .
You will see the following directories:
example
- our applicationcamera_view
- federated plugincamera_view
- Dart implementation of the interface and widgetscamera_view_platform_interface
- a common platform interface for thecamera_view
plugincamera_view_xxx
- platform implementations of the plugin
Try it out by running the example app on your desired device (iOS, Android, or macOS). There's VS Code launch configuration available.
This sample hosts camera previews on the following platforms:
Platform | Support |
---|---|
iOS | Yes |
Android | Yes |
macOS | Yes |
Windows | No |
Linux | No |
Web | No |
The iOS and macOS implementations use SwiftUI camera views from this article by Yono Mittlefehldt. The license note is included in every file copied from the original implementation.
The Android implementation uses CameraView library, which worked perfectly fine for this sample.
- macOS platform views don't handle gestures, throw exceptions when tapping anywhere even when ignoring touch events
- macOS platform views cannot be shown beneath the Flutter widgets thus there's not way to draw UI on top of the platform view
- window resizing on macOS is broken due to this threading issue
Contributions are welcome! If you'd like to improve existing implementation or propose new platform to be supported, please go ahead!