Building an AR App with Flutter

Nurettin Eraslan
3 min readJul 2, 2023

--

Flutter is a popular cross-platform mobile app development framework, while ARCore is an augmented reality (AR) platform provided by Google. By combining Flutter and ARCore, we can develop impressive AR experiences in mobile applications. In this article, we will learn how to use the arcore_flutter_plugin package in Flutter to build an AR app with examples.

What is arcore_flutter_plugin?

arcore_flutter_plugin is a package that allows us to leverage AR capabilities in Flutter applications. With arcore_flutter_plugin, we can overlay 3D objects on the camera view, perform face tracking, create anchor points, and more. This enables us to create immersive AR experiences.

Step 1: Setting up the Project Structure Before using arcore_flutter_plugin in a Flutter project, make sure you have Flutter SDK installed and the project is Flutter-compatible. Once you have Flutter SDK installed, you can create a new Flutter project. Next, add the arcore_flutter_plugin package to the pubspec.yaml file.

Step 2: Adding the arcore_flutter_plugin Package To use the arcore_flutter_plugin package in a Flutter project, add the following dependency to the pubspec.yaml file:

dependencies:
arcore_flutter_plugin: ^x.x.x

Replace x.x.x with the version number of the arcore_flutter_plugin package you are using. Then, update the Flutter project by running the command flutter pub get in the terminal.

Step 3: Using ARCore Features To use ARCore features with the arcore_flutter_plugin, follow these steps:

Import the arcore_flutter_plugin package:

import 'package:arcore_flutter_plugin/arcore_flutter_plugin.dart';

Initialize ARCore using the ARCoreController class:

ARCoreController arCoreController;

@override
void initState() {
super.initState();
arCoreController = ARCoreController();
}

@override
void dispose() {
arCoreController.dispose();
super.dispose();
}

Create the AR view using the ARView widget:

ARView(
onARViewCreated: arCoreController.onARViewCreated,
),

Place AR objects using the ARNode widget:

ARNode(
shape: ARCube(
materials: [
ARMaterial(
color: Colors.red,
),
],
size: Vector3(0.2, 0.2, 0.2),
),
position: Vector3(0, 0, -1),
),

In this example, we created a red cube as an AR object and positioned it at (-1, 0, 0).

Conclusion: In this article, we learned how to use the arcore_flutter_plugin package in Flutter to leverage ARCore features and build an AR app. The arcore_flutter_plugin package allows us to create immersive AR experiences in Flutter mobile applications. You can explore the documentation of arcore_flutter_plugin to learn more about its features and capabilities. With Flutter and ARCore, you can develop impressive AR applications.

Here Full Code App Example

import 'package:flutter/material.dart';
import 'package:arcore_flutter_plugin/arcore_flutter_plugin.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'AR Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ARScreen(),
);
}
}

class ARScreen extends StatefulWidget {
@override
_ARScreenState createState() => _ARScreenState();
}

class _ARScreenState extends State<ARScreen> {
ARCoreController arCoreController;

@override
void initState() {
super.initState();
arCoreController = ARCoreController();
}

@override
void dispose() {
arCoreController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('AR Demo'),
),
body: ARView(
onARViewCreated: arCoreController.onARViewCreated,
arCoreController: arCoreController,
enableTapRecognizer: true,
planeType: ARPlaneType.none,
enableUpdateListener: true,
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
arCoreController.addArCoreNode(
ARNode(
shape: ARCube(
materials: [
ARMaterial(
color: Colors.red,
),
],
size: Vector3(0.2, 0.2, 0.2),
),
position: Vector3(0, 0, -1),
),
);
},
),
);
}
}

--

--