olexale / arkit_flutter_plugin

ARKit Flutter Plugin
MIT License
796 stars 225 forks source link

"The simplest code example" does not compile #150

Open crcdng opened 3 years ago

crcdng commented 3 years ago

The initial example on https://pub.dev/packages/arkit_plugin does not compile with null-safe Flutter, two issues:

Vector3? pos = Vector3(0, 0, -0.5); and providing pos to position fixes the problem.

*Note that flutter automaticaly imports 'package:vector_math/vector_math.dart' instead of 'package:vector_math/vector_math64.dart' - this needs to be edited manually to fix another error that comes up.

After these modifiucations it works. I would recommend to test example code.

take2make commented 3 years ago

Can you share the correct example?

olexale commented 3 years ago

Hi. The example from the README works fine for me on Flutter 2.2.3 and the latest plugin. @i3games , does the example app works for you?

crcdng commented 3 years ago

it does not work with null-safe Flutter

Hi. The example from the README works fine for me on Flutter 2.2.3 and the latest plugin. @i3games , does the example app works for you?

while the library is null safe, the example is not. It therefore does not compile in null-safe Flutter. Two changes:

crcdng commented 3 years ago

Can you share the correct example?

import 'package:arkit_plugin/arkit_node.dart';
import 'package:arkit_plugin/geometries/arkit_sphere.dart';
import 'package:arkit_plugin/widget/arkit_scene_view.dart';
import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ARKitController? arkitController;
  Vector3? position = Vector3(0, 0, -0.5);

  void onARKitViewCreated(ARKitController arkitController) {
    this.arkitController = arkitController;
    final node = ARKitNode(
        geometry: ARKitSphere(radius: 0.1),
        position: position); // , position: Vector3(0, 0, -0.5)
    this.arkitController?.add(node);
  }

  @override
  void dispose() {
    arkitController?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
            appBar: AppBar(title: const Text('ARKit in Flutter')),
            body: ARKitSceneView(onARKitViewCreated: onARKitViewCreated)),
      );
}
olexale commented 3 years ago

I've updated the README with a working (at least for me) sample and ported the example app to null safety. Will push a new version 1.0.3 to pub.dev soon.