imaNNeo / imaNNeo/fl_chart

Line Chart Late Initialization Error with All-Null Bar Data

Open
#2,115 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
7.6k
Forks
2k
Avg merge
9d 1h
Merged PRs (30d)
2

Description

**Describe the bug**
Creating a line chart that contains barData with only `FlSpot.nullSpot`s causes `LineChartHelper.calculateMaxAxisValues` to throw a late initialization error.

**To Reproduce**

```dart
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text("FlChart Test")),
body: LineChart(
LineChartData(
lineBarsData: [
LineChartBarData(spots: [FlSpot(0, 0), FlSpot(1, 1)]),
LineChartBarData(spots: [FlSpot.nullSpot]),
],
),
),
),
);
}
}
```

Stack Trace

```
======== Exception caught by widgets library =======================================================
The following LateError was thrown building KeyedSubtree-[GlobalKey#bc0ba]:
LateInitializationError: Field 'mostRightSpot' has not been initialized.

The relevant error-causing widget was:
Scaffold Scaffold:file:///lib/main.dart:14:13
When the exception was thrown, this was the stack:
#0 LineChartBarData.mostRightSpot (package:fl_chart/src/chart/line_chart/line_chart_data.dart)
#1 LineChartHelper.calculateMaxAxisValues (package:fl_chart/src/chart/line_chart/line_chart_helper.dart:42:19)
#2 _LineChartState._getData (package:fl_chart/src/chart/line_chart/line_chart.dart:103:57)
#3 _LineChartState.forEachTween (package:fl_chart/src/chart/line_chart/line_chart.dart:166:7)
#4 ImplicitlyAnimatedWidgetState._constructTweens (package:flutter/src/widgets/implicit_animations.dart:423:5)
#5 ImplicitlyAnimatedWidgetState.initState (package:flutter/src/widgets/implicit_animations.dart:381:5)
#6 AnimatedWidgetBaseState.initState (package:flutter/src/widgets/implicit_animations.dart:558:11)
#7 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5950:55)
[215 more...]
(elided 3 frames from class _Timer and dart:async-patch)
====================================================================================================
```

**Screenshots**
If applicable, add screenshots, or videoshots to help explain your problem.

**Versions**

FlChart: 1.2.0

Flutter Doctor

```
> flutter doctor -v
[✓] Flutter (Channel stable, 3.44.5, on macOS 27.0 26A5388g darwin-arm64, locale en-US) [407ms]
• Flutter version 3.44.5 on channel stable at
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f94f4fc76b (3 weeks ago), 2026-07-06 11:19:24 -0700
• Engine revision 83675ed276
• Dart version 3.12.2
• DevTools version 2.57.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-swift-package-manager, omit-legacy-version-file,
enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.7s]
• Android SDK at
• Emulator version 35.5.10.0 (build_id 13402964) (CL:N/A)
• Platform android-36, build-tools 35.0.0
• Java binary at:
This JDK is specified in your Flutter configuration.
To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
• Java version Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
• All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 26.6) [3.2s]
• Xcode at
• Build 17F113
! CocoaPods 1.15.2 out of date (1.16.2 is recommended).
CocoaPods is a package manager for iOS or macOS platform code.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/to/platform-plugins
To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods

[✓] Chrome - develop for the web [5ms]
• Chrome at

[✓] Connected device (3 available) [7.6s]

[✓] Network resources [314ms]
• All expected network resources are available.

! Doctor found issues in 1 category.
```

Contributor guide

Open the contributing guide

Research direction

Start in lib/src/chart/line_chart/line_chart_helper.dart at calculateMaxAxisValues, then inspect LineChartBarData in lib/src/chart/line_chart/line_chart_data.dart and the call from lib/src/chart/line_chart/line_chart.dart. Reproduce the provided chart with a bar series containing only FlSpot.nullSpot. Done means the chart builds without a LateInitializationError while preserving the normal series behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.