Bug: Unsupported Operation (NaN) with nullSpots in fl_chart LineChart
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 7.6k
- Forks
- 2k
- Avg merge
- 9d 1h
- Merged PRs (30d)
- 2
Description
When using nullSpots in fl_chart's LineChart to split the line, the app crashes with a NaN exception during layout. This seems to be caused by a calculation error when handling null values in spots. Below is the full stack trace and relevant code.
**Steps to Reproduce:**
Use LineChart from fl_chart.
Set up the LineChartBarData with nullSpots to split the line into multiple segments.
Run the app and trigger the chart rendering.
Observe the crash and NaN exception.
**Expected Behavior:**
The nullSpots feature should split the lines without causing a crash. It should gracefully handle null values and render the chart properly.
**StackTrace**
```packages/flutter/src/rendering/object.dart 2627:7 layout
object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 117:21
proxy_box.dart:117
packages/flutter/src/rendering/object.dart 2627:7 layout
object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 117:21
proxy_box.dart:117
packages/flutter/src/rendering/object.dart 2627:7 layout
object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 117:21
proxy_box.dart:117
packages/flutter/src/rendering/object.dart 2627:7 layout
object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 586:12 performLayout
proxy_box.dart:586
packages/flutter/src/rendering/object.dart 2627:7 layout
object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 297:7 performLayout
proxy_box.dart:297
packages/flutter/src/rendering/object.dart 2627:7 layout
object.dart:2627
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
layout_helper.dart:61
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
flex.dart:1079
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
flex.dart:1121
packages/flutter/src/rendering/object.dart 2465:7 [_layoutWithoutResize]
object.dart:2465
packages/flutter/src/rendering/object.dart 1062:17 flushLayout
object.dart:1062
packages/flutter/src/rendering/object.dart 1075:14 flushLayout
object.dart:1075
packages/flutter/src/rendering/binding.dart 609:5 drawFrame
binding.dart:609
packages/flutter/src/widgets/binding.dart 1178:13 drawFrame
binding.dart:1178
packages/flutter/src/rendering/binding.dart 475:5 [_handlePersistentFrameCallback]
binding.dart:475
packages/flutter/src/scheduler/binding.dart 1397:7 [_invokeFrameCallback]
binding.dart:1397
packages/flutter/src/scheduler/binding.dart 1318:9 handleDrawFrame
binding.dart:1318
packages/flutter/src/scheduler/binding.dart 1176:5 [_handleDrawFrame]
binding.dart:1176
dart-sdk/lib/async/zone.dart 1414:13 _rootRun
zone.dart:1414
dart-sdk/lib/async/zone.dart 1317:19 run
zone.dart:1317
dart-sdk/lib/async/zone.dart 1225:7 runGuarded
zone.dart:1225
lib/_engine/engine/platform_dispatcher.dart 1410:9 invoke
platform_dispatcher.dart:1410
lib/_engine/engine/platform_dispatcher.dart 310:5 invokeOnDrawFrame
platform_dispatcher.dart:310
lib/_engine/engine/initialization.dart 187:36
initialization.dart:187
dart-sdk/lib/_internal/js_dev_runtime/patch/js_allow_interop_patch.dart 212:27 _callDartFunctionFast1
js_allow_interop_patch.dart:212
════════════════════════════════════════════════════════════════════════════════════════════════════
18
Another exception was thrown: Unsupported operation: NaN```
**Screenshot**

**Additional Context:**
The issue occurs when attempting to use nullSpots for splitting lines in the chart. It seems the library doesn't properly handle null values in the FlSpot list. Adding validation or better handling of null values might fix the issue.
Thanks in Advance!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the LineChart entry point and reproduce the crash with LineChartBarData using nullSpots to split the line. Trace how null values are handled during chart layout and verify that segmented lines render without an Unsupported operation: NaN exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100