Coffee & Code - Building an AR Solar System with Flutter and ARKit

Coffee & Code - Building an AR Solar System with Flutter and ARKit

See how I create 3D spheres, apply textures, and add rotation to build an interactive Augmented Reality Solar System using Flutter and Apple's ARKit.


Sample Image
Cappuccino from Segundo Coffee Lab at Ironworks in Houston, TX.

Applying that concept to reality, Augmented Reality (or AR) is a concept I’ve been interested in for a while but didn’t fully understand.

As usual, I researched AR technologies available in Flutter, and came across ARKit.

ARKit is Apple’s official software development kit that provides AR capabilities for your app.

Luckily, they have an official package for Flutter that’s easy to setup and build with.

Sample Image
Adding a white sphere to the scene.
import 'package:arkit_plugin/arkit_plugin.dart';
import 'package:vector_math/vector_math_64.dart' as vm;

// Contoller for udpating the ARKitView.
_arkitController = arkitController;

// Create white sphere node.
final whiteSphere = ARKitNode(
  name: 'White Sphere',
  geometry: ARKitSphere(
    radius: 0.5,
  ),
  position: vm.Vector3(0, 0, -3),
);

// Add to scene via the controller.
_arkitController.add(whiteSphere);
Sample Image
Adding an orange sphere to the scene.
import 'package:arkit_plugin/arkit_plugin.dart';
import 'package:vector_math/vector_math_64.dart' as vm;

// Update name.
final orangeSphere = ARKitNode(
  name: 'Orange Sphere',
  radius: 0.5,
  // Specify orange color.
  materials: [    ARKitMaterial(
      diffuse: ARKitMaterialProperty.color(Colors.orange),
    )
  ],
  position: vm.Vector3(0, 0, -4)
)
_arkitController.add(orangeSphere);
Sample Image
Adding a moon sphere to the scene.
import 'package:arkit_plugin/arkit_plugin.dart';
import 'package:vector_math/vector_math_64.dart' as vm;

// Update name.
final moon = ARKitNode(
  name: 'Moon',
  radius: 0.5,
  // Specify moon diffuse.
  materials: [    ARKitMaterial(=
      diffuse: ARKitMaterialProperty.image('assets/images/moon.jpg'),
    )
 ],
 position: vm.Vector3(0, 0, -4)
)
_arkitController.add(moon);
Sample Image
Rotating the moon sphere.
import 'package:arkit_plugin/arkit_plugin.dart';
void _rotateNodeOnXAxis(ARKitNode node, double pitch) {  
  // Rotate the node on its x-axis by pitch value.
  node.eulerAngles = node.eulerAngles..x += pitch;
}
_arkitController.updateAtTime = (time) {
  // Rotate node (moon) with moon spin speed.
  _rotateNodeOnXAxis(moon, Planets.moon.spinSpeed!);
};

You can watch my entire process of building an AR Solar System on YouTube.


Related posts
Coffee & Code - Rewriting My App, GetX to Riverpod

Coffee & Code - Rewriting My App, GetX to Riverpod

Read more
Coffee & Code - Gift Grab Power-Ups & App Store Improvements

Coffee & Code - Gift Grab Power-Ups & App Store Improvements

Read more
Coffee & Code - Deploying My Jaspr Site on Globe

Coffee & Code - Deploying My Jaspr Site on Globe

Read more
Coffee & Code - Nakama Sessions & Authentication

Coffee & Code - Nakama Sessions & Authentication

Read more