mirrored_repositories/flutter_ar
import 'package:flutter/material.dart';
import 'package:arcore_flutter_plugin/arcore_flutter_plugin.dart';
import 'package:vector_math/vector_math_64.dart' as vector;

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter AR'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  ArCoreController arCoreController;

  _onArCoreViewCreated(ArCoreController _arcoreController) {
    arCoreController = _arcoreController;
    _addSphere(arCoreController);
    _addCyclinder(_arcoreController);
    _addCube(_arcoreController);
  }

  _addSphere(ArCoreController _arcoreController) {
    final material  = ArCoreMaterial(color: Colors.yellow);
    final sphere = ArCoreSphere(materials: [material], radius: 0.2);
    final node = ArCoreNode(shape: sphere, position:  vector.Vector3(0,0,-1),);

    _arcoreController.addArCoreNode(node);  
  }

  _addCyclinder(ArCoreController _arcoreController) {
    final material  = ArCoreMaterial(color: Colors.grey, reflectance: 1);
    final cylinder = ArCoreCylinder(materials: [material], radius: 0.4, height: 0.3);
    final node = ArCoreNode(shape: cylinder, position:  vector.Vector3(0,-0.5,-3.0),);

    _arcoreController.addArCoreNode(node);  
  }

  _addCube(ArCoreController _arcoreController) {
    final material  = ArCoreMaterial(color: Colors.pink, metallic: 1);
    final cube = ArCoreCube(materials: [material], size: vector.Vector3(1,1,1));
    final node = ArCoreNode(shape: cube, position:  vector.Vector3(-0.5,-1.5,-4),);

    _arcoreController.addArCoreNode(node);  
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          widget.title,
        ),
      ),
      body: ArCoreView(
        onArCoreViewCreated: _onArCoreViewCreated,
        enableTapRecognizer: true,
      ),
    );
  }
}
