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

Commit

Permalink
fix: Adds hover support for web
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Soluk <isoluchok@gmail.com>
  • Loading branch information
soluchok committed Feb 7, 2021
1 parent 8dd8fa5 commit facc6c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
11 changes: 10 additions & 1 deletion charts_flutter/lib/src/chart_gesture_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:flutter/material.dart'
show
BuildContext,
GestureDetector,
MouseRegion,
ScaleEndDetails,
ScaleStartDetails,
ScaleUpdateDetails,
Expand Down Expand Up @@ -59,7 +60,9 @@ class ChartGestureDetector {
_listeningForLongPress = desiredGestures.contains(GestureType.onLongPress);

return new GestureDetector(
child: chartContainer,
child: new MouseRegion(
child: chartContainer,
onHover: (e) => onHover(e.position.dx, e.position.dy)),
onTapDown: wantTapDown ? onTapDown : null,
onTapUp: wantTap ? onTapUp : null,
onScaleStart: wantDrag ? onScaleStart : null,
Expand All @@ -68,6 +71,12 @@ class ChartGestureDetector {
);
}

void onHover(double x, y) {
final container = _containerResolver();
_lastTapPoint = new Point(x, y);
container.gestureProxy.onHover(_lastTapPoint);
}

void onTapDown(TapDownDetails d) {
final container = _containerResolver();
final localPosition = container.globalToLocal(d.globalPosition);
Expand Down
7 changes: 6 additions & 1 deletion charts_flutter/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import 'package:flutter/rendering.dart'
show
RenderBox,
RenderMouseRegion,
RenderSemanticsGestureHandler,
RenderPointerListener,
RenderCustomMultiChildLayoutBox;
Expand All @@ -36,9 +37,13 @@ ChartContainerRenderObject getChartContainerRenderObject(RenderBox box) {
(semanticHandler as RenderSemanticsGestureHandler).child;

assert(renderPointerListener is RenderPointerListener);
final chartContainerRenderObject =
final renderMouseRegion =
(renderPointerListener as RenderPointerListener).child;

assert(renderMouseRegion is RenderMouseRegion);
final chartContainerRenderObject =
(renderMouseRegion as RenderMouseRegion).child;

assert(chartContainerRenderObject is ChartContainerRenderObject);

return chartContainerRenderObject as ChartContainerRenderObject;
Expand Down
5 changes: 4 additions & 1 deletion charts_flutter/test/user_managed_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

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

Expand All @@ -35,7 +36,9 @@ void main() {

final testChart = new TestChart(selectionChangedListener, onTapSelection);

await tester.pumpWidget(testChart);
await tester.pumpWidget(MaterialApp(
home: testChart,
));

expect(currentSelectionModel, isNull);

Expand Down

0 comments on commit facc6c6

Please sign in to comment.