Building with flutter_scene
flutter_scene is a realtime 3D engine for Flutter, built on Flutter GPU. It has a retained scene graph (Scene holds Nodes, nodes carry a Mesh), physically based materials, image-based lighting, and a deep post-processing stack.
The one thing to internalize: this is not three.js, Godot, or Unity, and the API diverges from all three in specific ways. Most first-attempt failures come from reaching for another engine's spelling. The corrections below are the highest-value part of this skill; read them before writing code.
Do not reach for these (they do not exist or will break the build)
- Not the master channel. flutter_scene runs on Flutter 3.47 stable or newer. Do not run
flutter channel master; it resolves worse, not better. - Not
--enable-impeller, not--enable-experiment=native-assets. The run flag is--enable-flutter-gpuand nothing else.--enable-experiment=native-assetsactively breaks the build on Dart 3.10+. - Not
package:vector_math/vector_math_64.dart. flutter_scene usespackage:vector_math/vector_math.dart. The_64types are a different, incompatibleVector3. - Not
Node.fromAsset(...), notloadModel(...). Load a preprocessed model withloadScene('assets/x.glb')(returnsFuture<Node>), or a runtime glTF withNode.fromGlbAsset/Node.fromGlbBytes. - Not a hand-rolled
CustomPainter+Ticker. Display a scene with theSceneViewwidget; it drives the per-frame loop for you. - Not
node.position.set(x, y, z). See transforms below. - Not
forward.cross(up)for a camera or node right vector. View space is left-handed (+Zforward into the screen,+Yup,+Xright), whilevector_math'scrossis right-handed, soforward.cross(up)points screen-left and horizontally invertsA/Dstrafing and drag panning. Readcamera.right,camera.horizontalRight, ornode.right, or computeup.cross(forward).normalized(). - Not
.modelfiles orbuildModels. The offline format is.fsceneb, produced by theflutter_scene:initbuild hook; you load it by source path withloadScene. - Not the removed
Environmentclass. Environment lighting isEnvironmentMaponScene.environment.
Setup
flutter pub add flutter_scene
dart run flutter_scene:init # installs the build hook, sets up assets
flutter run --enable-flutter-gpu # native; add -d chrome for webflutter_scene:init is required setup, not optional. Rendering is gated on Scene.initializeStaticResources(); until it completes the engine prints "Flutter Scene is not ready to render. Skipping frame." If that load fails (a web build that could not fetch its shader bundle, say), a SceneView with an errorBuilder: (context, error, retry) shows it and calls retry() when the app chooses; nothing retries on its own, and without an errorBuilder the view reports the error and stays on its loading widget.
Minimal scene (this compiles as-is)
import 'package:flutter/material.dart';
import 'package:flutter_scene/scene.dart';
import 'package:vector_math/vector_math.dart' as vm;
void main() => runApp(const MaterialApp(home: CubeView()));
class CubeView extends StatefulWidget {
const CubeView({super.key});
@override
State<CubeView> createState() => _CubeViewState();
}
class _CubeViewState extends State<CubeView> {
final Scene scene = Scene();
bool ready = false;
@override
void initState() {
super.initState();
// Geometry and materials touch the shader bundle, so build them only
// after the engine's static resources are up.
Scene.initializeStaticResources().then((_) {
scene.add(Node(
mesh: Mesh(CuboidGeometry(vm.Vector3(1, 1, 1)), PhysicallyBasedMaterial()),
));
if (mounted) setState(() => ready = true);
});
}
@override
Widget build(BuildContext context) {
if (!ready) return const SizedBox.expand();
return SceneView(scene, camera: PerspectiveCamera(position: vm.Vector3(2, 2, -4)));
}
}An unset Scene.environment still gives image-based lighting (a default studio map is resolved at render), so a bare PhysicallyBasedMaterial() is lit without any light setup.
Choosing declarative or imperative
flutter_scene has two ways to build a scene, and picking the wrong one is a structural decision that is expensive to undo later. Choose up front by what the app does, not by which reads nicer.
Declarative (inline widgets). Describe the scene as Flutter widgets under SceneView.declarative(children: [...]), using SceneMesh, SceneNode, and SceneModel. Flutter's own rebuild diffing keeps the rendered scene in sync with your widget state, the same way it keeps the UI in sync. Reach for this when app state maps cleanly onto a fixed set of objects on screen and nothing is simulation-like, for example a product configurator where a few SceneMeshes track some setState values.
Imperative (retained scene graph). Own a Scene, add Nodes, attach Components, and display it with SceneView(scene, camera: ..., onTick: ...). Track state the way you would in another game engine. The cleanest shape is a plain Dart Game class that owns the Scene and holds the game state, with the scene build and per-frame tick routed into it, and behavior living in custom Components attached to nodes that the engine runs through the component lifecycle hooks. Reach for this for anything with real simulation.
Go imperative when the scene has complex physics, network replication, a character walking around, or procedural generation. Any one of these means imperative. Stay declarative when state maps directly to a fixed set of shown objects and nothing ticks or simulates.
The two interoperate. A mostly-declarative scene can drop to an imperative node where it needs one, and an imperative scene can mount declarative subtrees. See references/architecture.md for the Game-class pattern, component-driven nodes, and the hybrid seam.
The API shape (where it diverges from what you expect)
Transforms. Node has position, rotation (a Quaternion), and scale, but they are whole-value get/set, not the mutable spelling other engines use. Assign the whole vector (node.position = vm.Vector3(0, 1, 0) or node.position += ...). The getters return copies, so node.position.x = 5 does nothing and throws in debug. For a raw matrix edit use node.localTransform = matrix or node.mutateLocalTransform((m) => m.translateByVector3(...)); a bare in-place edit of node.localTransform never moves the node, because the cache is not told. node.forward, node.right, and node.up return the node's unit world-space basis axes (+Z, +X, +Y), and node.lookAt(target) or node.lookAtFrom(eye, target) aims local +Z at target.
Geometry. Ten built-in primitives (CuboidGeometry, SphereGeometry, IcosphereGeometry, CylinderGeometry with separate top/bottom radii so cones are free, CapsuleGeometry, TorusGeometry, PlaneGeometry, DiscGeometry, RingGeometry, WedgeGeometry), plus swept geometry (ExtrudeGeometry, TubeGeometry, RibbonGeometry), lines (PolylineGeometry), and GeometryBuilder/MeshData for custom meshes. Do not hand-pack a ByteData vertex buffer before checking these.
Materials. PhysicallyBasedMaterial (base color, metallic, roughness, normal, emissive, plus clearcoat/sheen/transmission/etc.), UnlitMaterial, ShaderMaterial for custom shaders. Texture slots take a TextureSource (from loadTexture(path)), not a raw gpu.Texture.
Camera and coordinate basis. PerspectiveCamera(position: ..., target: ...), or OrthographicCamera(position: ..., target: ..., projection: OrthographicProjection(size: OrthographicSize.height(12))) for isometric, top-down, and pixel-art views. Every depth effect works under both. Prefer attaching OrbitCameraController, FollowCameraController, or FlyCameraController to a camera node (driven with the CameraControls widget) over hand-rolling spherical camera math. When driving a camera yourself, remember that view space is left-handed (+Z forward into the screen, +Y up, +X right).
- Default camera placement sits on the
-Zside ((0, 0, -5)) looking along+Zat the origin, where world+Xpoints screen-right. If you instead place an eye on the+Zside (eye = target + vm.Vector3(d * sin(a), y, d * cos(a))) looking back along-Z, world+Xpoints screen-left (right = vm.Vector3(-cos(a), 0, sin(a))), not(cos(a), 0, -sin(a)). - Never write
forward.cross(up)for a right vector;vector_math's right-handed cross product makesforward.cross(up)point screen-left. Readcamera.right(orcamera.horizontalRightandcamera.horizontalForwardforXZground-plane strafing and panning) or computeup.cross(forward).normalized().
What you are probably underestimating (it is all here)
Models trained on older or thinner information assume flutter_scene has no lighting, no shadows, and no post-processing. It has all of it. Before hand-rolling any of these, know they exist: directional/point/spot/area lights, shadows (PCSS, contact shadows), GTAO ambient occlusion, screen-space reflections, parallax-corrected reflection probes, SSGI, depth of field, god rays, fog, auto exposure, LUT color grading, bloom, lens flares, MSAA/SMAA/FXAA, tone mapping, instancing, LOD. See references/what-exists.md for the full surface with the class names.
Low-end and GLES-class GPUs (Raspberry Pi, web, integrated Linux) get a budget, not a different engine: scene.renderQuality.tier (RenderQualityTier.low, medium, high; null picks the platform default) decides what AntiAliasingMode.auto and the scene color capture budget resolve to, and scene.renderQuality.adaptive = true lowers the render scale and then the tier from measured frame periods when frames overrun targetFrameRate. Transmissive (glass) materials are the expensive thing on such devices; scene.sceneColorCaptureBatches = 1 makes them all share one capture.
Traps that fail silently (wrong pixels, no error)
- Horizontal camera and movement inversion (
forward.cross(up)and+Zorbit tangents). Because view space has+Zinto the screen andvector_math.crossis right-handed,forward.cross(up)yields-right(screen-left), and an orbit camera placed attarget + (d * sin(a), y, d * cos(a))has screen-right(-cos(a), 0, sin(a)), not(cos(a), 0, -sin(a)). Usecamera.right,camera.horizontalRight,camera.horizontalForward, orup.cross(forward).normalized(). - Custom
ShaderMaterialoutput is linear HDR premultiplied by alpha. No tone mapping or gamma in your shader; theResolvePassapplies exposure, tone mapping, and the display transform. Linearize sRGB texture samples yourself. SeeMATERIALS.md. - Never hand-roll a per-triangle winding flip to fix glTF orientation. The importers handle the coordinate conversion; a manual flip leaves normals and IBL wrong.
- Do not emit a vertex buffer at the wrong stride. Unskinned is 72 bytes/vertex, skinned is 104; the attribute order is fixed. Use
GeometryBuilder, do not guess the layout. - Surfaces that share a plane flicker as the camera moves (z-fighting), and one screenshot can look fine.
- Never let two different-looking faces overlap in one plane. Repeated pieces abut (a piece's length equals its spacing), perpendicular runs meet at a corner post, and flat patches at one height never overlap. No depth setting fixes an exact overlap.
- An overlay that lies on a surface (a sign or screen on a wall, road paint, a decal quad, a rug) gets
material.depthLayer = 1and wins at any distance; an overlay on that overlay gets 2. Place it flush or a few millimetres off, not at a guessed gap. - Leave the camera's near plane at its default unless geometry clips. The engine fits the plane it rasterizes with to visible content every frame.
- Prove it in motion.
await scene.probeDepthConflicts()names every pair of nodes that trades pixels from a camera; drive itsconflictsto empty.scene.debug.overlays.add(DebugOverlay.depthConflicts)marks fights live in magenta, and debug builds print overlapping coplanar faces once the scene holds still.
- When pixels look wrong, look at the surface before guessing.
scene.debug.view = const DebugView(channel: SurfaceDebugChannel.roughness)(oruv0,worldNormal,baseColor,validation, anySurfaceDebugChannel) replaces the lit result with that value on every material,scene.debug.split = 0.5compares it against the lit half,scene.debug.overlays.add(DebugOverlay.wireframe)traces the mesh, andnode.debugView = DebugView.noneexcludes a subtree. The material channels need the views compiled in, which costs shader build time, so they are off by default: sethooks: user_defines: flutter_scene: debug_views: truein the app's pubspec (the workspace root's in a pub workspace), plusflutter_scene_debug_views: trueunder the app's own name if its hook callsbuildMaterialsorbuildEngineAssets, and rebuild. Without it only the geometry and identity channels draw, and the app prints how to turn them on. A.fmatshows any intermediate throughmaterial.debugand thecustomchannel.
More depth
references/architecture.mdfor the declarative-vs-imperative choice in depth, theGame-class pattern, component-driven nodes, and hybrid interop.references/what-exists.mdfor the full API surface (the false-absence fix).references/traps.mdfor the complete silent-failure list.references/depth-and-layering.mdfor why surfaces fight, a catalog of the overlaps generated content makes, and how to find and fix them.- The repo-root
MATERIALS.mdfor the custom-shader contract.
Keeping this skill current
This skill ships inside the flutter_scene package, so upgrading flutter_scene can carry a newer revision of it than the copy installed in the project. To check, run:
dart run flutter_scene:skills --checkIt reports the installed and bundled skill versions and exits non-zero when an update is available. If the installed flutter_scene ships a newer skill than what is installed, tell the user, since they are working against out-of-date guidance, and offer to update it with dart run flutter_scene:skills (which touches only the skill, not their build hook or pubspec). Worth a check when you start substantial flutter_scene work or when the user mentions upgrading the package.