Comments (4)
I have done some further testing and removing checkToShowDot
does not fix the memory leak.
But removing my touchCallback
does fix the memory leak.
I also tried keeping my callbacks for checkToShowDot
and touchCallback
but setting handleBuiltInTouches
to false
, this also doesn't fix the memory leak.
from fl_chart.
After even more testing:
I found if the callback I provide for touchCallback
contains ref
which is a WidgetRef
for riverpod I get this issue.
I changed the touchCallback
to this (I know its dumb code but I just wanted the bare minimum to make the issue happen):
touchCallback: (final FlTouchEvent ev, final LineTouchResponse? res) {
if (ref != null) {
}
}
I get the memory leak issue. None of my providers contain any FlSpots
so I am very confused at how this is happening.
from fl_chart.
I have done a memory snap shot and have discovered that it is more than just FlSpots
that are growing. First snap shot is on first draw of the charts and second snap shot is after a 5 second hover back and forth:
There are 4 charts with 2 lines each in this example.
from fl_chart.
Here is a full main.dart
to reproduce the issue. It is much simpler with only having one chart:
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fl_chart/fl_chart.dart';
void main() {
runApp(const ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Column(
children: [
Expanded(child: Chart(),),
Expanded(child: Chart(),),
]
)
)
),
theme: ThemeData(useMaterial3: true),
);
}
}
final testProvider = StateProvider<int>((ref) => 0);
class Chart extends ConsumerWidget {
Chart({super.key});
static const int _numberOfLines = 3;
static const int _numberOfDataPoints = 1500;
@override
Widget build(BuildContext context, WidgetRef ref) {
final int index = ref.watch(testProvider);
return LineChart(
LineChartData(
lineTouchData: LineTouchData(
handleBuiltInTouches: false,
touchSpotThreshold: 20,
touchCallback: (final FlTouchEvent ev, final LineTouchResponse? res) {
ref.read(testProvider.notifier).state = res?.lineBarSpots?.first.spotIndex ?? 0;
},
),
gridData: const FlGridData(show: false),
borderData: FlBorderData(show: false),
lineBarsData: _buildLineData(index),
),
);
}
List<LineChartBarData> _buildLineData(final int index) {
final List<LineChartBarData> lineData = <LineChartBarData>[];
for (int i = 0; i < _numberOfLines; ++i) {
lineData.add(LineChartBarData(
showingIndicators: <int>[index],
dotData: FlDotData(show: false),
spots: () {
return List<FlSpot>.generate(
_numberOfDataPoints,
(index) {
return FlSpot(index.toDouble(), index.toDouble());
}
);
}()
));
}
return lineData;
}
}
You will see that there are 3 lines with 1500
spots each and when you start this app it starts with 4501
FlSpot
objects. Then if you hover this just grows and grows and doesn't stop (other objects grow as well).
Required dependencies:
fl_chart: ^0.67.0
flutter_riverpod: ^2.5.1
from fl_chart.
Related Issues (20)
- `belowBarData` does not fit the size of the line chart's start and end
- How can I draw a horizntol line from the last dot in LineChart? HOT 1
- PieChart: touched section index is incorrect if some values are zero HOT 1
- ScatterChart: Show label for a spot HOT 1
- sidetitle overloading each others
- 2 ToolTip top & bottom
- Best way to synchronize and show tool tips of an X value across multiple charts HOT 1
- [Feature Request] RadarChartTitle
- How to deal with small section in pie chart?
- preventCurveOverShooting sounds like mitigation rather than solution HOT 1
- Strange rounding when the x values are 0 HOT 8
- it's posible to do scrollbar on line chart like attachment?
- BottomTitles for each bar in BarChart
- [Live graph] Errors such as noise in the live graph
- PieTouchData not working on some sections
- Overlapping labels, label alignment - add workaround to documentation
- ScatterChart doesn't support rangeAnnotation.
- Bug: Linux Example App build fails HOT 1
- Add Segment Selection to LineChart
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fl_chart.