Home > OS >  how to disable scrollview when pinch zoom in image
how to disable scrollview when pinch zoom in image

Time:09-08

I am using the lib pinch_zoom_release_unzoom to pinch zoom image. I create it inside SingleChildScrollView but when user use 2 finger to pinch zoom image. it very hard to zoom because sometime page is Scrollable. so I want to solve this problem

CodePudding user response:

You can interact with physics of scrollable widget to make scrolling different. For that purpose, you should change your physic inside SingleChildScrollView , whenever your zooming state changes. For example:

lass ParentWidget extends StatefulWidget {
  const ParentWidget ({Key? key,}) : super(key: key);


  @override
  State<ParentWidget > createState() => _ParentWidgetState();
}

class _ParentWidgetState extends State<ParentWidget > {
 late bool isScrolling;

  @override
  void initState() {
    isScrolling = false;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return  SingleChildScrollView(
          physics: isScrolling ? NeverScrollableScrollPhysics() : null,
    child: YourWidget(function: (currentState) => setState(() {
          isScrolling = currentState;
           }));

class YourWidget extends StatelessWidget {
  const SceneManaging({Key? key, this.callback}) : super(key: key);
  final Function(bool isScrolling)? function;

}

In this case, you should call function inside your child widget whenever you use zoom. When it zooms - pass to it a true, to disable your parent widget scroll, whenever zooms actions stops - pass false.

CodePudding user response:

physics: NeverScrollableScrollPhysics()


How the scroll view should respond to user input.

For example, determines how the scroll view continues to animate after the user stops dragging the scroll view.

Defaults to matching platform conventions. Furthermore, if primary is false, then the user cannot scroll if there is insufficient content to scroll, while if primary is true, they can always attempt to scroll.

To force the scroll view to always be scrollable even if there is insufficient content, as if primary was true but without necessarily setting it to true, provide an AlwaysScrollableScrollPhysics physics object, as in:

physics: const AlwaysScrollableScrollPhysics(), To force the scroll view to use the default platform conventions and not be scrollable if there is insufficient content, regardless of the value of primary, provide an explicit ScrollPhysics object, as in:

physics: const ScrollPhysics(), The physics can be changed dynamically (by providing a new object in a subsequent build), but new physics will only take effect if the class of the provided object changes. Merely constructing a new instance with a different configuration is insufficient to cause the physics to be reapplied. (This is because the final object used is generated dynamically, which can be relatively expensive, and it would be inefficient to speculatively create this object each frame to see if the physics should be updated.)

  • Related