Home

Awesome

logo

Codemagic build status flutter awesome pub package

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 or newer is required. Flutter >=3.19.0 supports iOS 12.0 and newer, if iOS 11 support is needed use the plugin version before 1.1.0.

Usage

Add dependency

Follow the installation instructions from Dart Packages site.

Update Info.plist

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>

Update Podfile

At the top level of the ios folder uncomment the second line in the Podfile and change the iOS minimum version from 9.0 to the appropriate one. The minimum supported iOS version is 12.0. For body tracking minimum version must be 13.0.

From:

# platform :ios, '9.0'

To:

platform :ios, '12.0'

NOTE: If when running for the first time you get a cocoapods error, delete the Podfile.lock file in the ios folder. Open the ios folder in the terminal and run:

pod install

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> {
  late 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:

flutter

Examples

I would highly recommend to review the sample from the Example folder inside the plugin. Some samples rely on this Earth image

NameDescriptionLinkDemo
Hello WorldThe simplest scene with different geometries.codetwitter
Check configurationShows which kinds of AR configuration are supported on the devicecode
EarthSphere with an image texture and rotation animation.codetwitter
TapSphere which handles tap event.codetwitter
MidasTurns walls, floor, and Earth itself into gold by tap.codetwitter
Plane DetectionDetects horizontal plane.codetwitter
Distance trackingDetects horizontal plane and track distance on it.codetwitter
MeasureMeasures distancescodetwitter
PhysicsA sphere and a plane with dynamic and static physicscodetwitter
Image DetectionDetects Earth photo and puts a 3D object near it.codetwitter
Network Image DetectionDetects Mars photo and puts a 3D object near it.code
Custom LightHello World scene with a custom light spot.code
Light EstimationEstimates and applies the light around you.codetwitter
Custom ObjectPlace custom object on plane with coaching overlay.codetwitter
Load .gltf .glbLoad .gltf or .glb from the Flutter assets or the Documents folder.code
OcclusionSpheres which are not visible after horizontal and vertical planes.codetwitter
ManipulationCustom objects with pinch and rotation events.codetwitter
Face TrackingFace mask sample.codetwitter
Body TrackingDash that follows your hand.codetwitter
Panorama360 photo.codetwitter
Video360 video.codetwitter
Custom AnimationCustom object animation. Port of https://github.com/eh3rrera/ARKitAnimationcodetwitter
Widget ProjectionFlutter widgets in ARcodetwitter
Real Time UpdatesCalls a function once per framecode
SnapshotMake a photo of AR contentcode

If you prefer video here is a playlist with "AR in Flutter" videos:

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.

If your app requires placing objects consider using coaching overlays. Review the Custom Object 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'] = '$(inherited) -DDISABLE_TRUEDEPTH_API'
    end
  end
end

FAQ

dependencies:
  arkit_plugin:
    git: git://github.com/olexale/arkit_flutter_plugin.git

Contributing

If you find a bug or would like to request a new feature, just open an issue. Your contributions are always welcome!