arkit_flutter_plugin
Short intro: Flutter Plugin for ARKit – Apple’s augmented reality (AR) development platform for iOS mobile devices.
Note: ARKit is only supported by mobile devices with A9 or later processors (iPhone 6s/7/SE/8/X, iPad 2017/Pro) on iOS 11 and newer. For some features iOS 12 is required.
Usage
Depend on it
Follow the installation instructions from Dart Packages site.
Update Info.plist
The plugin use native view from ARKit, which is not yet supported by default. To make it work add the following code to Info.plist
:
<key>io.flutter.embedded_views_preview</key> <string>YES</string>
ARKit uses the device camera, so do not forget to provide the NSCameraUsageDescription
. You may specify it in Info.plist
like that:
<key>NSCameraUsageDescription</key> <string>Describe why your app needs AR here.</string>
Write the app
The simplest code example:
import 'package:flutter/material.dart'; import 'package:arkit_plugin/arkit_plugin.dart'; import 'package:vector_math/vector_math_64.dart'; void main() => runApp(MaterialApp(home: MyApp())); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { ARKitController arkitController; @override void dispose() { arkitController?.dispose(); super.dispose(); } @override Widget build(BuildContext context) => Scaffold( appBar: AppBar(title: const Text('ARKit in Flutter')), body: ARKitSceneView(onARKitViewCreated: onARKitViewCreated)); void onARKitViewCreated(ARKitController arkitController) { this.arkitController = arkitController; final node = ARKitNode( geometry: ARKitSphere(radius: 0.1), position: Vector3(0, 0, -0.5)); this.arkitController.add(node); } }
Result:
Examples
I would highly recommend to review the sample from the Example
folder. You may find a couple of samples in the Example
folder of the plugin. Some samples rely on this Earth image
Name | Description | Link | Demo |
---|---|---|---|
Hello World | The simplest scene with different geometries. | code | |
Earth | Sphere with an image texture and rotation animation. | code | |
Tap | Sphere which handles tap event. | code | |
Plane Detection | Detects horizontal plane. | code | |
Distance tracking | Detects horizontal plane and track distance on it. | code | |
Measure | Measures distances | code | |
Physics | A sphere and a plane with dynamic and static physics | code | |
Image Detection | Detects Earth photo and puts a 3D object near it. | code | |
Network Image Detection | Detects Mars photo and puts a 3D object near it. | code | |
Custom Light | Hello World scene with a custom light spot. | code | |
Light Estimation | Estimates and applies the light around you. | code | |
Custom Object | Place custom object on plane. | code | |
Occlusion | Spheres which are not visible after horizontal and vertical planes. | code | |
Manipulation | Custom objects with pinch and rotation events. | code | |
Face Tracking | Face mask sample. | code | |
Panorama | 360 photo. | code | |
Custom Animation | Custom object animation. Port of https://github.com/eh3rrera/ARKitAnimation | code | |
Widget Projection | Flutter widgets in AR | code |
If you prefer video here is a playlist with “AR in Flutter” videos:
UX advice
You might want to check the device capabilities before establishing an AR session. Review the Check Support sample for the implementation details.
Before you go to AppStore
The plugin supports TrueDepth API. In case you didn’t use it, your app will be rejected by Apple. Hence you need to remove any TrueDepth functionality by modifying your Podfile
file
post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| ... # Here are some configurations automatically generated by flutter config.build_settings['OTHER_SWIFT_FLAGS'] = '-DDISABLE_TRUEDEPTH_API' end end end
Contributing
If you find a bug or would like to request a new feature, just open an issue. Your contributions are always welcome!
Download ARKit Flutter Plugin source code on GitHub
https://github.com/olexale/arkit_flutter_plugin
Check out Flutter Plugin for ARKit implementation guide on Pub
https://pub.dev/packages/arkit_plugin
Provides the list of the opensource Flutter apps collection with GitHub repository.