siliconsorcery / flutter_stage

Position widgets in a 3D scene

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flutter Stage

pub package

A widget that positions its children in a 3D scene.

Update

Silicon Sorcery, Feb 9, 2023:

  • Changed code to make it null-safe for use in Flutter v3.x
  • Added some bitmaps to cube faces.

Getting Started

Add flutter_stage as a dependency in your pubspec.yaml file.

dependencies:
  flutter_stage: ^0.0.1

Import package.

import 'package:flutter_stage/flutter_stage.dart';
... ...
  
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Stage(
        onSceneCreated: (Scene scene) {
          scene.camera.position.setFrom(Vector3(0, 0, 1000));
          scene.camera.updateTransform();
        },
        children: [
          Actor(
            position: Vector3(0, 0, 0),
            rotation: Vector3(0, 30, 0),
            children: [
              Actor(position: Vector3(0, 0, 300), rotation: Vector3(0, 0, 0), width: 600, height: 600, widget: Container(color: Colors.red.withOpacity(0.5))),
              Actor(position: Vector3(300, 0, 0), rotation: Vector3(0, 90, 0), width: 600, height: 600, widget: Container(color: Colors.green.withOpacity(0.5))),
              Actor(position: Vector3(0, 0, -300), rotation: Vector3(0, 180, 0), width: 600, height: 600, widget: Container(color: Colors.blue.withOpacity(0.5))),
              Actor(position: Vector3(-300, 0, 0), rotation: Vector3(0, 270, 0), width: 600, height: 600, widget: Container(color: Colors.yellow.withOpacity(0.5))),
              Actor(position: Vector3(0, -300, 0), rotation: Vector3(90, 0, 0), width: 600, height: 600, widget: Container(color: Colors.pink.withOpacity(0.5))),
              Actor(position: Vector3(0, 300, 0), rotation: Vector3(270, 0, 0), width: 600, height: 600, widget: Container(color: Colors.white.withOpacity(0.5)))
            ],
          ),
        ],
      ),
    );
  }

Screenshot

screenshot

Flutter Clock Challenge submission

About

Position widgets in a 3D scene

License:Apache License 2.0


Languages

Language:Dart 83.2%Language:Ruby 8.9%Language:Swift 5.9%Language:Kotlin 1.3%Language:HTML 0.6%Language:Objective-C 0.1%