Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to capture GestureDetector for onScaleUpdate and onScaleEnd #1183

Open
mars000 opened this issue Nov 3, 2022 · 12 comments
Open

how to capture GestureDetector for onScaleUpdate and onScaleEnd #1183

mars000 opened this issue Nov 3, 2022 · 12 comments
Labels
enhancement New feature or request Fundamental

Comments

@mars000
Copy link

mars000 commented Nov 3, 2022

Hi
I'm trying to capture a pinch to zoom action by using GestureDector as per below,
I can confirm it first onDoubleTap but not for onLongPress, onScaleUpdae or onScaleEnd.
Is it something I'd doing wrong ?
any help would be much appreciated.

child: GestureDetector(
                child: LineChart(
                  // showAvg ? avgData() : mainData(),
                  mainData(),
                ),
                onDoubleTap: () {
                  print(
                      '61-[line_chart_sample2.dart] onDoubleTap gesture triggered');   // this fires! and i get print statemt when I doubletap
                },
                onLongPress: () {
                  print(
                      '61-[line_chart_sample2.dart] onLongPress gesture triggered');  // this does not fire
                },
                onScaleUpdate: (details) {
                  print(
                      '61-[line_chart_sample2.dart] onScaleUpdate details = $details'); // this does not fire
                },
                onScaleEnd: (ScaleEndDetails details) {
                  print(
                      '61-[line_chart_sample2.dart] onScaleUpdate details = $details'); // this does not fire
                },
              ),
@dLogicC
Copy link

dLogicC commented Nov 21, 2022

Hi I'm trying to capture a pinch to zoom action by using GestureDector as per below, I can confirm it first onDoubleTap but not for onLongPress, onScaleUpdae or onScaleEnd. Is it something I'd doing wrong ? any help would be much appreciated.

child: GestureDetector(
                child: LineChart(
                  // showAvg ? avgData() : mainData(),
                  mainData(),
                ),
                onDoubleTap: () {
                  print(
                      '61-[line_chart_sample2.dart] onDoubleTap gesture triggered');   // this fires! and i get print statemt when I doubletap
                },
                onLongPress: () {
                  print(
                      '61-[line_chart_sample2.dart] onLongPress gesture triggered');  // this does not fire
                },
                onScaleUpdate: (details) {
                  print(
                      '61-[line_chart_sample2.dart] onScaleUpdate details = $details'); // this does not fire
                },
                onScaleEnd: (ScaleEndDetails details) {
                  print(
                      '61-[line_chart_sample2.dart] onScaleUpdate details = $details'); // this does not fire
                },
              ),

Hi, did you find a solution? I have the same problem.

@mars000
Copy link
Author

mars000 commented Nov 22, 2022

I found if you enable gestures in FL_CHART then it traps all gesture messages and does not process or pass through all gestures :-(
If I disabled handleBuiltInTouches: true, i.e. set to false then my GestureDetector would capture the gestures. Its not ideal but a crude workaround. Perhaps someone else has a more elegant approach ?

@dLogicC
Copy link

dLogicC commented Nov 22, 2022

I found the same solution.
I think a better approach is to edit the "RenderBaseChart" class in the "render_base_chart.dart" file in order to catch the scale event.
Were you able to get a good pinch-to-zoom effect?

@mars000
Copy link
Author

mars000 commented Nov 22, 2022

I like your idea - much neater.
I did not actually implement code to pinch-to-zoom...in the end I just implemented a simple slider below graph that dynamically adjusted zoom factor of graph .... was neater and fingers get in the way in viewing the graph on a small screen i found :-)

@imaNNeo
Copy link
Owner

imaNNeo commented Jan 15, 2023

Can you please tell me what you want to do?
Are you looking for a zoom feature?
If yes, please follow this issue: #71

@mars000
Copy link
Author

mars000 commented Jan 15, 2023 via email

@imaNNeo
Copy link
Owner

imaNNeo commented Jan 16, 2023

Okay so let's only talk about the gesture here.
For the scroll feature you can follow the mentioned issue.

@imaNNeo imaNNeo added enhancement New feature or request Fundamental labels Jan 16, 2023
@mars000
Copy link
Author

mars000 commented Jun 18, 2023

Sorry @imaNNeo what do you mean by the statement “mentioned issue” ?
Is there anyway you can pass through the pinch zoom gesture so I can write the code to process it…from my understanding this is not passed through therefore I am unable to react to it.

@imaNNeo
Copy link
Owner

imaNNeo commented Jul 3, 2023

I meant #71
There are some workarounds introduced by people

@TNorbury
Copy link

Hello, I created a fork with a proposed solution (see commit here). Basically it replaces pan gestures with scale gestures. Scale gestures are a superset of pan gestures (source), so I think that's a safe swap as developers will just be able to check the number of pointers being used to determine if they want to pan or scale.

In my code, which now has pinch to zoom and horizontal panning, my LineTouchData.touchCallback now looks like this:

case FlScaleUpdateEvent:
  {
    event = event as FlScaleUpdateEvent;
    if (event.details.pointerCount == 1) {
      chartController.onHorizontalDrag(
            context,
            deltaX: event.details.focalPointDelta.dx,
          );
    } else {
      chartController.onScale(scaleDetails: event.details);
    }
  }

My fork is just a hacked together version that works for my app's needs, but more than happy to work with you @imaNNeo to make it something that could be merged in

@TNorbury
Copy link

Here's an example of how it works, I currently use: long press, tap, and scale to achieve this
chart_scale

@extrame
Copy link

extrame commented Jun 14, 2024

I tested the solution of @TNorbury , It work only on PanGestureRecognizer disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Fundamental
Projects
None yet
Development

No branches or pull requests

5 participants