model_viewer_plus.dart icon indicating copy to clipboard operation
model_viewer_plus.dart copied to clipboard

Rotation controls broken after showing a dialog

Open frantovar opened this issue 2 years ago • 3 comments

Describe the bug After showing a dialog over the modelViewer the model controls start failing and rotation don't work anymore. You can check the video here.

To reproduce Steps to reproduce the behavior:

  1. Place a dialog in the app bar. Check this example.
  2. Show the dialog
  3. Close it
  4. Now rotation controls are broken

Expected behavior After closing the dialog the model should be controller normally.

Simulator and real device

  • OS: iOS
  • Version 15.2

Additional context Add any other context about the problem here.

frantovar avatar Jan 19 '23 19:01 frantovar

Have you found a solution? I have the same problem using ModelViewer inside IndexedStack.

Problem code
return IndexedStack(
  index: stackIndex,
  children: [
    ModelViewer(
      id: "modelViewBlock",
      src:
          "https://modelviewer.dev/shared-assets/models/Astronaut.glb",
      ar: false,
      autoRotate: true,
      cameraControls: true,
      loading: Loading.eager,
      touchAction: TouchAction.none,
      enablePan: false,
      disableZoom: false,
      interactionPolicy: InteractionPolicy.alwaysAllow,
    ),
    Container(color: Colors.amber),
  ],
);

I've tried to reproduce such problem with WebView, but it works fine:

WebView solution
return IndexedStack(
  index: stackIndex,
  children: [
    WebView(
      backgroundColor: Colors.transparent,
      initialUrl: "https://modelviewer.dev/",
      javascriptMode: JavascriptMode.unrestricted,
      initialMediaPlaybackPolicy:
          AutoMediaPlaybackPolicy.always_allow,
      gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
        Factory<OneSequenceGestureRecognizer>(
          () => EagerGestureRecognizer(),
        ),
      },
    ),
    Container(color: Colors.amber),
  ],
);

Any ideas what it could be?

LesGrob avatar Feb 01 '23 12:02 LesGrob

I figured out that the problem isn't with Stack but with widgets in it. There is what i mean: If there are widgets in Stack above ModelViewer then ModelViewer’s gesture detector cracks after clicking on any widget above it. Here is code to reproduce problem:

return Scaffold(
      body: Stack(children: [
        ModelViewer(
          id: "modelViewBlock",
          src: "https://modelviewer.dev/shared-assets/models/Astronaut.glb",
          ar: false,
          backgroundColor: Colors.green,
          loading: Loading.eager,
          cameraControls: true,
          touchAction: TouchAction.none,
          enablePan: false,
          disableZoom: false,
          autoRotate: true,
        ),
        Positioned(
          bottom: 20 + MediaQuery.of(context).padding.bottom,
          left: 40,
          width: 40,
          height: 40,
          child: Container(color: Colors.red),
        ),
      ]),
    );

It can be fixed by covering above widgets with IgnorePointer:

return Scaffold(
      body: Stack(children: [
        ModelViewer(
          id: "modelViewBlock",
          src: "https://modelviewer.dev/shared-assets/models/Astronaut.glb",
          ar: false,
          backgroundColor: Colors.green,
          loading: Loading.eager,
          cameraControls: true,
          touchAction: TouchAction.none,
          enablePan: false,
          disableZoom: false,
          autoRotate: true,
        ),
        Positioned(
          bottom: 20 + MediaQuery.of(context).padding.bottom,
          left: 40,
          width: 40,
          height: 40,
          child: IgnorePointer(
            child: Container(color: Colors.red),
          ),
        ),
      ]),
    );

But it’s still problem to use GestureDetectors above ModelViewer. I think ModelViewer make "+1 pan" after clicking on widget. So after one click it start to zoom model when only one finger on screen. And absolutely stucks after the second tap. Here is video: https://user-images.githubusercontent.com/44160618/218119132-81b333f5-7298-4256-a566-c8df0ffbf168.mp4

LesGrob avatar Feb 10 '23 14:02 LesGrob

07/01/2023, the error persists. I still can't click on the buttons on the scene with the model. Has anyone found a solution? And this problem is reproduced only on ios. On Android devices, all buttons work correctly

hellhorse123 avatar Jul 01 '23 05:07 hellhorse123