How to Use 3D Models in Flutter?
Last Updated :
10 May, 2025
Flutter has recently developed into the realm of 3D graphics, expanding its capabilities beyond just 2D applications. In this article, we will explore the exciting process of creating 3D objects in Flutter using the flutter_cube library.
Steps to Implement 3D Models in Flutter
Step 1: Create a new Flutter Application
Create a new Flutter application using the command Prompt. To create a new app, write the following command and run it.
flutter create app_name
To know more about it refer this article: Creating a Simple Application in Flutter
Step 2: Adding the Dependency
To add the dependency to the pubspec.yaml file, add flutter_cube as a dependency in the dependencies part of the pubspec.yaml file, as shown below:
Dart
dependencies:
flutter:
sdk: flutter
flutter_cube: ^0.1.1
Now, run the command below in the terminal.
flutter pub get
Or
Run the below command in the terminal.
flutter pub add flutter_cube
Step 3: Import dependencies
To use libraries, import all of them in the main.dart file,
Dart
import 'package:flutter_cube/flutter_cube.dart';
Step 4: Import assets
Create a folder named "assets" in the "lib/" path and download the below-provided folders, and put them in the assets folder.
After that, give their paths in pubspec.yaml.
flutter:
uses-material-design: true
assets:
- assets/jet/
- assets/shark/
Step 5: Working with main.dart
Add the boilerplate code below in main.dart to create a basic structure with an AppBar and body using a Scaffold.
Dart
import 'package:flutter/material.dart';
import 'package:flutter_cube/flutter_cube.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter 3D',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
title: Text("Flutter 3D"),
),
body: Container(
// Code Here
),
);
}
}
Step 6: Initialize variables
Initialize the required variables in the _HomePageState class.
Dart
// Declare a variable to hold the 3D model of the jet
late Object jet;
// Declare a variable to hold the 3D model of the shark
late Object shark;
@override
void initState() {
// Load the 3D model of the jet
jet = Object(fileName: "assets/jet/Jet.obj");
// Load the 3D model of the shark
shark = Object(fileName: "assets/shark/shark.obj");
// Rotate the shark model
shark.rotation.setValues(0, 90, 0);
// Update the transformation of the shark model
shark.updateTransform();
super.initState();
}
Step 7: Create 3D Objects
Let's delve into the code of creating 3D objects using flutter_cube.
Shark
Expanded(
child: Cube(
onSceneCreated: (Scene scene) {
// Add the shark model to the scene
scene.world.add(shark);
// Set the camera zoom level
scene.camera.zoom = 10;
},
),
),
Jet
Expanded(
child: Cube(
onSceneCreated: (Scene scene) {
// Add the jet model to the scene
scene.world.add(jet);
// Set the camera zoom level
scene.camera.zoom = 10;
},
),
),
Step 8: Develop UI
- Column: Wrap both shark and jet in a column.
Dart
Column(
children: [
Expanded(
child: Cube(
onSceneCreated: (Scene scene) {
// Add the shark model to the scene
scene.world.add(shark);
// Set the camera zoom level
scene.camera.zoom = 10;
},
),
),
Expanded(
child: Cube(
onSceneCreated: (Scene scene) {
// Add the jet model to the scene
scene.world.add(jet);
// Set the camera zoom level
scene.camera.zoom = 10;
},
),
),
],
),
Complete Source Code
main.dart:
Dart
import 'package:flutter/material.dart';
import 'package:flutter_cube/flutter_cube.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter 3D',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
// Declare a variable to hold the 3D model of the jet
late Object jet;
// Declare a variable to hold the 3D model of the shark
late Object shark;
@override
void initState() {
// Load the 3D model of the jet
jet = Object(fileName: "assets/jet/Jet.obj");
// Load the 3D model of the shark
shark = Object(fileName: "assets/shark/shark.obj");
// Rotate the shark model
shark.rotation.setValues(0, 90, 0);
// Update the transformation of the shark model
shark.updateTransform();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// Set the background color of the app bar
backgroundColor: Colors.green,
// Set the foreground color of the app bar
foregroundColor: Colors.white,
// Set the title of the app bar
title: Text("Flutter 3D"),
),
body: Container(
child: Column(
children: [
Expanded(
child: Cube(
onSceneCreated: (Scene scene) {
// Add the shark model to the scene
scene.world.add(shark);
// Set the camera zoom level
scene.camera.zoom = 10;
},
),
),
Expanded(
child: Cube(
onSceneCreated: (Scene scene) {
// Add the jet model to the scene
scene.world.add(jet);
// Set the camera zoom level
scene.camera.zoom = 10;
},
),
),
],
),
),
);
}
}
Click Here to access the whole application code.
Output :
Conclusion
With Flutter's ongoing advancements, app development is reaching new creative heights. It is opening doors to incredibly immersive experiences for users everywhere. So, jump into the exciting world of 3D and let your imagination run wild.
Similar Reads
Flutter - How to Use SVG Image
SVG (Scalable Vector Graphics) is a vector image format that can be used to create high-quality, resolution-independent graphics. In Flutter, you can use SVG images to display vector graphics in your app. To use SVG images in Flutter, you can use the  flutter_svg package to display SVG images in Flu
3 min read
How to Use ZegoCloud in Flutter?
In Flutter there are many prebuild Audio_Room_kit For Example - Agora, ZegoClooud LiveKit etc., but In this article, we are going to use ZegoCloud Live Audio Room Kit, use this SDK to add real-time video, audio and data features to your Flutter app. Connecting to a self- or cloud-hosted ZegoCloud se
3 min read
How to Install Flutter on Windows?
Flutter is Google's portable user interface (UI) toolkit. It is used to build and develop eye-catching, natively built mobile, desktop, and web applications from a single codebase. Flutter is free, open-sourced, and compatible with existing code. Due to its user-friendly interface and fairly simple
8 min read
How to Add Splash Screen in Flutter App?
We all have heard of Flutter right, it's a cross-platform application development tool. Flutter can be used to make Android, IOS, and Web applications with just one code base (Dart programming language). In this article let's see how we can add a splash screen to our applications. What is Splash Scr
3 min read
Flutter - How to Integrate Mapbox
Maps have become an aspect of our routines. Whether you're exploring a city looking for a coffee shop or keeping tabs on delivery maps is incredibly valuable. When it comes to creating apps incorporating maps not only improves the user experience but is also frequently necessary, for applications th
7 min read
Mail and SMS in Flutter
The world works in text. From advertisements to conversations, text is everywhere. The most popular modes of official textual communication are Mail followed by SMS. Companies use these modes to communicate not only with their employees but also with their customers. This has led app developers to i
5 min read
How to Install Flutter in Eclipse?
Flutter is a framework for building cross-platform applications (android, ios, web) which use Dart as its programming language. Before IDEs like Android Studio and VS code became popular, Eclipse used to be heavily used by developers. Now we can install dart inside our Eclipse IDE with the help of t
2 min read
How to Install Flutter App on Android?
The hottest and trending cross-platform framework, Flutter is Google's SDK for crafting beautiful, fast user experiences for mobile, web, and desktop with just a single codebase, meaning you write for one, build for three. Flutter works with existing code, is used by developers and organizations aro
4 min read
How to Run Gradle Build in Flutter?
Gradle is a tool that is used to automate tasks in android development. The Gradle build is one specific task that can be used to create APK files for your app. Often, the flutter run/build tasks don't work as desired, and in those cases, cleaning and building the Gradle again can be helpful. There
2 min read
How to Deploy Flutter Web App on Netlify?
In this article, we will deploy a counter flutter web app which is a single page application on Netlify. What is Netlify?It is a web development platform that makes CI/CD, deployment, and scaled hosting. It supports multiple frameworks which include Flutter. It does not require money to deploy websi
3 min read