arkit_plugin 0.4.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

arkit_flutter_plugin #

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

flutter

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

NameDescriptionLinkDemo
Hello WorldThe simplest scene with different geometries.codetwitter
EarthSphere with an image texture and rotation animation.codetwitter
TapSphere which handles tap event.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 an earth image and puts a 3D object near it.codetwitter
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.codetwitter
OcclusionSpheres which are not visible after horizontal and vertical planes.codetwitter
ManipulationCustom objects with pinch and rotation events.codetwitter
Face TrackingFace mask sample.codetwitter
Panorama360 photo.codetwitter
Custom AnimationCustom object animation. Port of https://github.com/eh3rrera/ARKitAnimationcodetwitter
Widget ProjectionFlutter widgets in ARcodetwitter

UX advice #

You might want to check the device capabilities before establishing an AR session. To do that the device_info plugin will be in hand. Check the documentation about AR functionality you want to add and implement some fallback logic for users with older OSes.

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['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        'REQUIRE_TRUEDEPTH_API=0',
      ]
    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!

Changelog #

0.4.1 #

  • Added updateAtTime function, enables real-time updates.
  • Added performHitTest function.

0.4.0 #

  • Major serialization/deserialization enhancement

0.3.1 #

  • Body tracking

0.3.0 #

  • Flutter Widgets in AR
  • Bug fixes

0.2.2 #

  • Custom animations
  • Material property network image
  • Material property image might be loaded from Flutter project (by @Topazoo)

0.2.1 #

  • Basic Face Tracking functionality
  • Add ARWorldAlignment
  • doubleSided property is added to material

0.2.0 #

  • Cover all ARKit geometries
  • Made all core properties of all geometries ValueNotifiers

0.1.2 #

  • ARKitNode.renderingOrder
  • Both Horizontal and Vertical planes option
  • Option to handle taps not in real position, but at the center of the widget.
  • Rotation improved
  • onSessionWasInterrupted and onSessionInterruptionEnded handlers added

0.1.1 #

  • Tap Gesture refactored to onNodeTap and onARTap
  • SKReferenceNode wrapped

0.1.0 #

  • Image detection
  • ARKitLine
  • Custom light
  • Light estimation

0.0.3 #

  • ARKitNode added
  • Add debug options: world origin, feature points
  • ARPlaneAnchor added
  • Physics added
  • Plane tap event handler added

0.0.2 #

  • Plane detection enum implemented
  • ARKitSceneView.autoenablesDefaultLighting property implemented
  • Documentation added
  • Materials implementation
  • Plane and text geometries
  • Basic tap gesture recognizer added
  • Position and rotation change handling

0.0.1 #

  • PoC of the ARKit port
  • Sphere added

example/lib/main.dart

import 'package:arkit_plugin_example/custom_animation_page.dart';
import 'package:arkit_plugin_example/custom_object_page.dart';
import 'package:arkit_plugin_example/distance_tracking_page.dart';
import 'package:arkit_plugin_example/custom_light_page.dart';
import 'package:arkit_plugin_example/earth_page.dart';
import 'package:arkit_plugin_example/hello_world.dart';
import 'package:arkit_plugin_example/image_detection_page.dart';
import 'package:arkit_plugin_example/light_estimate_page.dart';
import 'package:arkit_plugin_example/manipulation_page.dart';
import 'package:arkit_plugin_example/measure_page.dart';
import 'package:arkit_plugin_example/occlusion_page.dart';
import 'package:arkit_plugin_example/physics_page.dart';
import 'package:arkit_plugin_example/plane_detection_page.dart';
import 'package:arkit_plugin_example/tap_page.dart';
import 'package:arkit_plugin_example/face_detection_page.dart';
import 'package:arkit_plugin_example/panorama_page.dart';
import 'package:arkit_plugin_example/widget_projection.dart';
import 'package:arkit_plugin_example/real_time_updates.dart';
import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(home: MyApp()));

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final samples = [
      Sample(
        'Hello World',
        'The simplest scene with all geometries.',
        Icons.home,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => HelloWorldPage())),
      ),
      Sample(
        'Earth',
        'Sphere with an image texture and rotation animation.',
        Icons.language,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => EarthPage())),
      ),
      Sample(
        'Tap',
        'Sphere which handles tap event.',
        Icons.touch_app,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => TapPage())),
      ),
      Sample(
        'Plane Detection',
        'Detects horizontal plane.',
        Icons.blur_on,
        () => Navigator.of(context).push<void>(
            MaterialPageRoute(builder: (c) => PlaneDetectionPage())),
      ),
      Sample(
        'Distance tracking',
        'Detects horizontal plane and track distance on it.',
        Icons.blur_on,
        () => Navigator.of(context).push<void>(
            MaterialPageRoute(builder: (c) => DistanceTrackingPage())),
      ),
      Sample(
        'Measure',
        'Measures distances',
        Icons.linear_scale,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => MeasurePage())),
      ),
      Sample(
        'Physics',
        'A sphere and a plane with dynamic and static physics',
        Icons.file_download,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => PhysicsPage())),
      ),
      Sample(
        'Image Detection',
        'Detects an earth image and puts a 3D object near it.',
        Icons.collections,
        () => Navigator.of(context).push<void>(
            MaterialPageRoute(builder: (c) => ImageDetectionPage())),
      ),
      Sample(
        'Custom Light',
        'Hello World scene with a custom light spot.',
        Icons.lightbulb_outline,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => CustomLightPage())),
      ),
      Sample(
        'Light Estimation',
        'Estimates and applies the light around you.',
        Icons.brightness_6,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => LightEstimatePage())),
      ),
      Sample(
        'Custom Object',
        'Place custom object on plane.',
        Icons.nature,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => CustomObjectPage())),
      ),
      Sample(
        'Occlusion',
        'Spheres which are not visible after horizontal and vertical planes.',
        Icons.blur_circular,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => OcclusionPage())),
      ),
      Sample(
        'Manipulation',
        'Custom objects with pinch and rotation events.',
        Icons.threed_rotation,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => ManipulationPage())),
      ),
      Sample(
        'Face Tracking',
        'Face mask sample.',
        Icons.face,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => FaceDetectionPage())),
      ),
      Sample(
        'Panorama',
        '360 photo sample.',
        Icons.panorama,
        () => Navigator.of(context)
            .push<void>(MaterialPageRoute(builder: (c) => PanoramaPage())),
      ),
      Sample(
        'Custom Animation',
        'Custom object animation. Port of https://github.com/eh3rrera/ARKitAnimation',
        Icons.accessibility_new,
        () => Navigator.of(context).push<void>(
            MaterialPageRoute(builder: (c) => CustomAnimationPage())),
      ),
      Sample(
        'Widget Projection',
        'Flutter widgets in AR',
        Icons.widgets,
        () => Navigator.of(context).push<void>(
            MaterialPageRoute(builder: (c) => WidgetProjectionPage())),
      ),
      Sample(
        'Real Time Updates',
        'Calls a function once per frame',
        Icons.timer,
        () => Navigator.of(context).push<void>(
            MaterialPageRoute(builder: (c) => RealTimeUpdatesPage())),
      ),
    ];

    return Scaffold(
      appBar: AppBar(
        title: const Text('ARKit Demo'),
      ),
      body:
          ListView(children: samples.map((s) => SampleItem(item: s)).toList()),
    );
  }
}

class SampleItem extends StatelessWidget {
  const SampleItem({Key key, this.item}) : super(key: key);
  final Sample item;

  @override
  Widget build(BuildContext context) {
    return Card(
      child: InkWell(
        onTap: () => item.onTap(),
        child: ListTile(
          leading: Icon(item.icon),
          title: Text(
            item.title,
            style: Theme.of(context).textTheme.subhead,
          ),
          subtitle: Text(
            item.description,
            style: Theme.of(context).textTheme.subtitle,
          ),
        ),
      ),
    );
  }
}

class Sample {
  const Sample(this.title, this.description, this.icon, this.onTap);
  final String title;
  final String description;
  final IconData icon;
  final Function onTap;
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  arkit_plugin: ^0.4.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:arkit_plugin/arkit_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
83
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/light/arkit_light.g.dart. (-0.50 points)

Analysis of lib/light/arkit_light.g.dart reported 1 hint:

line 9 col 12: The declaration '_$ARKitLightFromJson' isn't referenced.

Fix lib/light/arkit_light_estimate.g.dart. (-0.50 points)

Analysis of lib/light/arkit_light_estimate.g.dart reported 1 hint:

line 17 col 22: The declaration '_$ARKitLightEstimateToJson' isn't referenced.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
json_annotation ^3.0.0 3.0.1
meta ^1.1.8 1.1.8
vector_math ^2.0.8 2.0.8
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
Dev dependencies
build_runner ^1.7.2
flutter_test
json_serializable ^3.2.3