CariusLars / ar_flutter_plugin

Flutter Plugin for AR (Augmented Reality) - Supports ARKit on iOS and ARCore on Android devices
MIT License
333 stars 254 forks source link

GestureDetector widget cause issue in object rotation #194

Open nayanAubie opened 1 year ago

nayanAubie commented 1 year ago

I've used the GestureDetector widget for hiding the keyboard when the user taps outside of a TextField. For that, I am using this widget in the builder callback of MaterialApp.

main.dart

MaterialApp(
    /// other code
    builder: (context, child) {
    return GestureDetector(
    // For removing focus and closing the keyboard when clicking on whitespace portion
    onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
    child: child!,
   );
  },
)

ar_view.dart

Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        elevation: 0,
        backgroundColor: Colors.transparent,
      ),
      body: ARView(
        onARViewCreated: _onARViewCreated,
        planeDetectionConfig: PlaneDetectionConfig.horizontal,
      ),
)

Future<void> _onARViewCreated(
    ARSessionManager arSessionManager,
    ARObjectManager arObjectManager,
    ARAnchorManager arAnchorManager,
    ARLocationManager arLocationManager,
  ) async {
    this.arSessionManager = arSessionManager;
    this.arObjectManager = arObjectManager;
    this.arAnchorManager = arAnchorManager;

    this.arSessionManager.onInitialize(
          handlePans: true,
          handleRotation: true,
          showWorldOrigin: true,
          customPlaneTexturePath: 'assets/images/triangle.png',
        );
    this.arObjectManager.onInitialize();
    this.arSessionManager.onPlaneOrPointTap = _onPlaneOrPointTapped;
  }

Future<void> _onPlaneOrPointTapped(
    List<ARHitTestResult> hitTestResults,
  ) async {
/// Adding object to the surface
}

An object was placed successfully when I tap any surface point, I can able to drag it, but can't rotate it even after handleRotation: true. If I remove the GestureDetector widget from main.dart then it's working. but I can't remove it.

everoo commented 1 year ago

Maybe try messing with the .behavior of the GestureDetector my hope is doing HitTestBehavior.translucent would work. If not maybe wrapping the child in a SizedBox.expand() could work. Neither of those are guarantees but flutter has some weird ways of dealing with taps, and I've had both of those help in the past.

nayanAubie commented 1 year ago

This won't work as I need to hide keyboard when user taps anywhere in the screen