Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Tap and drag selection for chart in PageView #237

Open
altherat opened this issue Apr 8, 2019 · 3 comments
Open

Tap and drag selection for chart in PageView #237

altherat opened this issue Apr 8, 2019 · 3 comments

Comments

@altherat
Copy link

altherat commented Apr 8, 2019

I'm having an issue where SelectionTrigger.tapAndDrag does not work when the chart is in a PageView because the PageView is a handling the drag. I'm fairly new to Flutter so maybe there's a standard way to fix this, but I've tried a few things such as surrounding the chart with AbsorbPointer but it doesn't help.

Here's a sample application demonstrating the issue:

import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: PageView(
          children: <Widget>[
            charts.TimeSeriesChart(
              [charts.Series<TimeSeriesEntry, DateTime>(
                domainFn: (TimeSeriesEntry entry, _) => entry.time,
                measureFn: (TimeSeriesEntry entry, _) => entry.value,
                data: [
                  TimeSeriesEntry(DateTime(2015, 1, 1), 0),
                  TimeSeriesEntry(DateTime(2016, 1, 1), 5),
                  TimeSeriesEntry(DateTime(2017, 1, 1), 10),
                  TimeSeriesEntry(DateTime(2018, 1, 1), 5),
                  TimeSeriesEntry(DateTime(2019, 1, 1), 10),
                ]
              )],
              behaviors: [
                charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag)
              ],
            ),
            Text("Page 2")
          ],
        )
      )
    );
  }
}

class TimeSeriesEntry {

  final DateTime time;
  final int value;

  TimeSeriesEntry(this.time, this.value);

}
@lukepighetti
Copy link

lukepighetti commented Sep 15, 2020

I know it's been a while but if you use NeverScrollablePhysics() on the parent page view it will stop it from scrolling while you're doing another action. As far as prioritizing the chart swipe action over the page view swipe action, I don't know how to do that. We generally do not design apps to have two swipe actions in the same direction.

@apoleo88
Copy link

I had a similar issue and used PageScrollPhysics() it allowed me to scroll the page and to capture the callback from the chart.

@Alb3it
Copy link

Alb3it commented Feb 27, 2022

I had a similar issue and used PageScrollPhysics() it allowed me to scroll the page and to capture the callback from the chart.

Did you mean you prioritize the horizontal chart scroll over the vertical pageview scroll? I'm dealing with this issue... Could you explain me how you solved that problem?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants