Workaround for timeline bar chart selection bug (#1382)
* Workaround for timeline bar chart selection bug
diff --git a/packages/devtools_app/lib/src/timeline/flutter/flutter_frames_chart.dart b/packages/devtools_app/lib/src/timeline/flutter/flutter_frames_chart.dart
index 2946b20..33913c4 100644
--- a/packages/devtools_app/lib/src/timeline/flutter/flutter_frames_chart.dart
+++ b/packages/devtools_app/lib/src/timeline/flutter/flutter_frames_chart.dart
@@ -5,7 +5,6 @@
import 'dart:ui';
import 'package:flutter/material.dart';
-import 'package:flutter/scheduler.dart';
import 'package:mp_chart/mp/chart/bar_chart.dart';
import 'package:mp_chart/mp/controller/bar_chart_controller.dart';
import 'package:mp_chart/mp/core/adapter_android_mp.dart';
@@ -29,6 +28,7 @@
import '../../flutter/auto_dispose_mixin.dart';
import '../../flutter/controllers.dart';
+import '../../ui/colors.dart';
import '../../ui/fake_flutter/_real_flutter.dart';
import '../../ui/theme.dart';
import '../timeline_controller.dart';
@@ -188,7 +188,7 @@
drawBarShadow: false,
description: desc,
highLightPerTapEnabled: true,
- marker: SelectedDataPoint(onSelected: frameSelected),
+ marker: SelectedDataPoint(onSelected: onBarSelected),
selectionListener: this,
);
@@ -196,16 +196,10 @@
_chartController.setViewPortOffsets(50, 10, 10, 30);
}
- void frameSelected(int frameIndex) {
- _controller.frameBasedTimeline.selectFrame(frames[frameIndex]);
+ void onBarSelected(int index) {
+ _controller.frameBasedTimeline.selectFrame(frames[index]);
}
- /// Light Blue 50 - 200
- static const mainUiColorLight = Color.fromARGB(0xff, 0x81, 0xD4, 0xFA);
-
- /// Light Blue 50 - 700
- static const mainGpuColorLight = Color.fromARGB(0xFF, 0x02, 0x88, 0xD1);
-
void _initData([bool simulateFeed = false]) {
// Create place holder for empty chart.
// TODO(terry): Look at fixing MPFlutterChart to handle empty data entries.
@@ -213,7 +207,7 @@
// Create heap used dataset.
frameDurationsSet = BarDataSet(_frameDurations, 'Durations')
- ..setColors1([mainGpuColorLight, mainUiColorLight])
+ ..setColors1([mainGpuColor, mainUiColor])
..setDrawValues(false);
// Create a data object with all the data sets - stacked bar.
@@ -330,7 +324,6 @@
const paddingAroundText = 5;
const rectangleCurve = 5.0;
- final frameIndex = _entry.x.toInt();
final yValues = (_entry as BarEntry).yVals;
final num uiDuration = yValues[1];
@@ -376,21 +369,16 @@
);
painter.paint(canvas, pos);
canvas.restore();
-
- if (onSelected != null && _lastFrameIndex != frameIndex) {
- // Only fire when a different frame is selected.
- // TODO(terry): reconfigure this code as selection should not be happening
- // during paint. This task scheduling is a hack.
- SchedulerBinding.instance.scheduleTask(
- () => onSelected(frameIndex),
- Priority.animation,
- );
- _lastFrameIndex = frameIndex;
- }
}
@override
- void refreshContent(Entry e, Highlight highlight) {
+ void refreshContent(Entry e, Highlight highlight) async {
_entry = e;
+ final frameIndex = _entry.x.toInt();
+ if (onSelected != null && _lastFrameIndex != frameIndex) {
+ _lastFrameIndex = frameIndex;
+ WidgetsBinding.instance
+ .addPostFrameCallback((_) => onSelected(frameIndex));
+ }
}
}