o3d 2.0.0 copy "o3d: ^2.0.0" to clipboard
o3d: ^2.0.0 copied to clipboard

The Flutter 3D objects easy controller ( glb format ) on mobile and web platforms

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'O3D Viewer',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'O3D Viewer'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // to control the animation
  O3DController controller = O3DController();
  List<String> logs = [];
  bool cameraControls = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
        actions: [
          IconButton(
              onPressed: () => controller.cameraOrbit(20, 20, 5),
              icon: const Icon(Icons.change_circle)),
          IconButton(
              onPressed: () => controller.cameraTarget(1.2, 1, 4),
              icon: const Icon(Icons.change_circle_outlined)),
          IconButton(
              onPressed: () => {
                    cameraControls = !cameraControls,
                    controller.cameraControls = cameraControls
                  },
              icon: const Icon(Icons.camera_alt_outlined)),
        ],
      ),
      body: O3D(
          controller: controller,
          src: 'https://modelviewer.dev/shared-assets/models/Astronaut.glb'
          //   //'https://assets.babakcode.com/flutter/projects/ui_3d_flutter/'
          //   'assets/glb/'
          //   'jeff_johansen_idle.glb',
          ),
    );
  }
}