Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syncfusion_flutter_charts 27.1.56 error 'value != null': is not true. #2152

Open
ChurikiTenna opened this issue Oct 29, 2024 · 1 comment
Open
Labels
charts Charts component waiting for customer response Cannot make further progress until the customer responds.

Comments

@ChurikiTenna
Copy link

Bug description

Error:

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building KeyedSubtree-[GlobalKey#3ca71]:
flutter: 'package:syncfusion_flutter_charts/src/charts/axis/axis.dart': Failed assertion: line 3560 pos 12:
flutter: 'value != null': is not true.
flutter:
flutter: The relevant error-causing widget was:
flutter:   KeyedSubtree-[GlobalKey#3ca71]
flutter:   KeyedSubtree:file:///Users/tenna/.pub-cache/hosted/pub.dev/syncfusion_flutter_charts-27.1.55/lib/src/charts/common/core_legend.dart:501:17

However, yValue is never null:

LineSeries dataSeries() {
return LineSeries<GraphData, String>(
yAxisName: "体重",
color: AppColors.darkColor,
dataSource: widget.otherValues!,
xValueMapper: (GraphData data, _) => data.name,
yValueMapper: (GraphData data, _) =>
0,
markerSettings: const MarkerSettings(
isVisible: false, shape: DataMarkerType.circle),
animationDuration: 200,
emptyPointSettings:
EmptyPointSettings(mode: EmptyPointMode.drop, borderWidth: 1),
dashArray: [2, 4],
onPointTap: (detail) {
debugPrint("onPointTap ${detail.pointIndex}");
});
}

Steps to reproduce

Throw any value in datas field below.

Code sample

Code sample
class GraphData {
  var name = "";
  var value = 0.0;
  Color? color;
  Color? color2;

  GraphData(this.name, this.value, {this.color, this.color2});
}

class GraphWidget extends StatefulWidget {
  const GraphWidget(this.datas,
      {super.key,
      this.otherValues,
      this.showXAxis = true,
      this.color = AppColors.darkColor,
      this.wd});
  final double? wd;
  final Color color;
  final bool showXAxis;
  final List<GraphData> datas;
  final List<GraphData>? otherValues;

  @override
  State<GraphWidget> createState() => _GraphWidgetState();
}

class _GraphWidgetState extends State<GraphWidget> {
  TrackballBehavior? _trackballBehavior;

  double get min {
    int min = 100;
    for (var data in widget.datas) {
      if (data.value != 0 && data.value < min) {
        min = data.value.toInt();
      }
    }
    for (var data in widget.otherValues ?? []) {
      if (data.value != 0 && data.value < min) {
        min = data.value.toInt();
      }
    }
    min -= 5;
    while (min % 5 != 0) {
      min -= 1;
    }
    return min.toDouble();
  }

  double get max {
    int min = 20;
    for (var data in widget.datas) {
      if (data.value > min) {
        min = data.value.toInt();
      }
    }
    for (var data in widget.otherValues ?? []) {
      if (data.value > min) {
        min = data.value.toInt();
      }
    }
    min += 5;
    while (min % 5 != 0) {
      min += 1;
    }
    return min.toDouble();
  }

  double ht() {
    return MyScreen.safeH() * 0.34;
  }

  double oneGridH() {
    var count = max - min;
    return (ht() - 40) / count;
  }

  @override
  void initState() {
    super.initState();
    _trackballBehavior = TrackballBehavior(
        enable: true, activationMode: ActivationMode.singleTap);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        color: Colors.white,
        padding: const EdgeInsets.fromLTRB(4, 4, 4, 8),
        child: SizedBox(
            height: ht(),
            child: Column(
              children: [
                Expanded(
                    child: Stack(children: [
                  charts(),
                  weightLbl(),
                  temprLbl(),
                ])),
                widget.showXAxis ? xAxis() : Container()
              ],
            )));
  }

  Widget weightLbl() {
    try {
      var percent = (max - widget.datas.first.value) * oneGridH() + 10;
      if (widget.datas.first.value == 0) {
        return Container();
      }
      return Container(
        margin: EdgeInsets.only(left: 40, top: percent),
        child: Texts.n12("体重(kg)", color: AppColors.darkColor),
      );
    } catch (e) {
      return Container();
    }
  }

  Widget temprLbl() {
    try {
      var percent = (max - widget.otherValues!.first.value) * oneGridH() + 10;
      if (widget.otherValues!.first.value == 0) {
        return Container();
      }
      return Container(
        margin: EdgeInsets.only(left: 40, top: percent),
        child: Texts.n12("体温(℃)", color: AppColors.darkColor),
      );
    } catch (e) {
      return Container();
    }
  }

  Widget charts() {
    return SfCartesianChart(
      enableAxisAnimation: true,
      borderWidth: 0,
      plotAreaBorderWidth: 0,
      primaryYAxis: NumericAxis(
          interval: 5,
          minimum: min,
          maximum: max,
          axisLine: const AxisLine(width: 0),
          majorTickLines: const MajorTickLines(width: 0)),
      series: <CartesianSeries>[] +
          (widget.otherValues != null ? [dataSeries()] : []) +
          [otherDataSeries()],
      primaryXAxis: CategoryAxis(isVisible: false),
      trackballBehavior: _trackballBehavior,
    );
  }

  Widget xAxis() {
    var list = <String>[];
    if (widget.datas.length < 10) {
      list = widget.datas.map((e) => e.name).toList();
    } else {
      list = [widget.datas.first.name, widget.datas.last.name];
    }
    return Padding(
      padding: const EdgeInsets.only(left: 50, right: 20),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: list
            .map((e) => Container(
                  alignment: Alignment.center,
                  padding: const EdgeInsets.fromLTRB(4, 2, 3, 3),
                  child: Texts.n12(e),
                ))
            .toList(),
      ),
    );
  }

  LineSeries dataSeries() {
    return LineSeries<GraphData, String>(
        yAxisName: "体重",
        color: AppColors.darkColor,
        dataSource: widget.otherValues!,
        xValueMapper: (data, _) => data.name,
        yValueMapper: (data, _) => data.value,
        markerSettings: const MarkerSettings(
            isVisible: false, shape: DataMarkerType.circle),
        animationDuration: 200,
        emptyPointSettings:
            EmptyPointSettings(mode: EmptyPointMode.drop, borderWidth: 1),
        dashArray: [2, 4],
        onPointTap: (detail) {
          debugPrint("onPointTap ${detail.pointIndex}");
        });
  }

  LineSeries otherDataSeries() {
    return LineSeries<GraphData, String>(
        yAxisName: "体温",
        color: widget.color,
        dataSource: widget.datas,
        xValueMapper: (data, _) => data.name,
        yValueMapper: (data, _) => data.value,
        markerSettings: widget.datas.length <= 40
            ? const MarkerSettings(
                isVisible: false,
                width: 10,
                height: 10,
                shape: DataMarkerType.circle)
            : const MarkerSettings(),
        animationDuration: 200,
        emptyPointSettings: EmptyPointSettings(
            mode: EmptyPointMode.drop,
            color: Colors.red,
            borderColor: Colors.red,
            borderWidth: 2),
        onPointTap: (detail) {
          debugPrint("onPointTap ${detail.pointIndex}");
        });
  }
}

class ChartData {
  ChartData(this.x, this.y, this.y1);
  final String x;
  final double y;
  final double y1;
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Stack Traces

Stack Traces
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building KeyedSubtree-[GlobalKey#3ca71]:
flutter: 'package:syncfusion_flutter_charts/src/charts/axis/axis.dart': Failed assertion: line 3560 pos 12:
flutter: 'value != null': is not true.
flutter:
flutter: The relevant error-causing widget was:
flutter:   KeyedSubtree-[GlobalKey#3ca71]
flutter:   KeyedSubtree:file:///Users/tenna/.pub-cache/hosted/pub.dev/syncfusion_flutter_charts-27.1.55/lib/src/charts/common/core_legend.dart:501:17
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2      AxisDependent.yAxis= (package:syncfusion_flutter_charts/src/charts/axis/axis.dart:3560:12)
flutter: #3      CartesianSeriesRenderer.yAxis= (package:syncfusion_flutter_charts/src/charts/series/chart_series.dart:3437:11)
flutter: #4      RenderCartesianAxes.performUpdate.<anonymous closure> (package:syncfusion_flutter_charts/src/charts/base.dart:2029:27)
flutter: #5      ContainerRenderObjectMixin.visitChildren (package:flutter/src/rendering/object.dart:4443:14)
flutter: #6      RenderCartesianAxes.performUpdate (package:syncfusion_flutter_charts/src/charts/base.dart:2021:30)
flutter: #7      ChartAreaUpdateMixin.update (package:syncfusion_flutter_charts/src/charts/base.dart:164:5)
flutter: #8      RenderCartesianChartArea._update (package:syncfusion_flutter_charts/src/charts/base.dart:859:23)
flutter: #9      ChartAreaRenderObjectElement.mount (package:syncfusion_flutter_charts/src/charts/base.dart:104:15)
flutter: ...     Normal element mounting (7 frames)
flutter: #16     Element.inflateWidget (package:flutter/src/widgets/framework.dart:4468:16)
flutter: #17     Element.updateChild (package:flutter/src/widgets/framework.dart:3963:18)
flutter: #18     SlottedRenderObjectElement._updateChildren (package:flutter/src/widgets/slotted_render_object_widget.dart:295:33)
flutter: #19     SlottedRenderObjectElement.mount (package:flutter/src/widgets/slotted_render_object_widget.dart:249:5)
flutter: ...     Normal element mounting (35 frames)
flutter: #54     Element.inflateWidget (package:flutter/src/widgets/framework.dart:4468:16)
flutter: #55     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:7035:36)
flutter: #56     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:7047:32)
flutter: ...     Normal element mounting (7 frames)
flutter: #63     Element.inflateWidget (package:flutter/src/widgets/framework.dart:4468:16)
flutter: #64     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:7035:36)
flutter: #65     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:7047:32)
flutter: ...     Normal element mounting (24 frames)
flutter: #89     Element.inflateWidget (package:flutter/src/widgets/framework.dart:4468:16)
flutter: #90     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:7035:36)
flutter: #91     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:7047:32)
flutter: ...     Normal element mounting (10 frames)
flutter: #101    Element.inflateWidget (package:flutter/src/widgets/framework.dart:4468:16)
flutter: #102    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:7035:36)
flutter: #103    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:7047:32)
flutter: ...     Normal element mounting (83 frames)
flutter: #186    Element.inflateWidget (package:flutter/src/widgets/framework.dart:4468:16)
flutter: #187    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:7035:36)
flutter: #188    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:7047:32)
flutter: #189    Element.inflateWidget (package:flutter/src/widgets/framework.dart:4468:16)
flutter: #190    Element.updateChild (package:flutter/src/widgets/framework.dart:3957:20)
flutter: #191    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
flutter: #192    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
flutter: #193    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
flutter: #194    BuildScope._tryRebuild (package:flutter/src/widgets/framework.dart:2693:15)
flutter: #195    BuildScope._flushDirtyElements (package:flutter/src/widgets/framework.dart:2752:11)
flutter: #196    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3048:18)
flutter: #197    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1162:21)
flutter: #198    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:468:5)
flutter: #199    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
flutter: #200    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1318:9)
flutter: #201    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
flutter: #202    _invoke (dart:ui/hooks.dart:312:13)
flutter: #203    PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
flutter: #204    _drawFrame (dart:ui/hooks.dart:283:31)
flutter: (elided 2 frames from class _AssertionError)
flutter:
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════

On which target platforms have you observed this bug?

iOS

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.1.1 23B81 darwin-arm64, locale ja-JP)
    • Flutter version 3.24.3 on channel stable at /Users/tenna/developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (7 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/tenna/Library/Android/sdk
    • Platform android-35, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.94.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.98.0

[✓] Connected device (6 available)
    • tenna’s iphone15 (mobile)       • 00008120-00120DDA1E10A01E                • ios            • iOS 18.1 22B82
    • Tenna’s iPad (mobile)           • d1802c9bcfe7b9b836383ca90361f9c15180f21e • ios            • iOS 17.6.1 21G93
    • Tenna’s iPhone11 (mobile)       • 00008030-0012304A01D3402E                • ios            • iOS 17.6.1 21G93
    • macOS (desktop)                 • macos                                    • darwin-arm64   • macOS 14.1.1 23B81 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                    • darwin         • macOS 14.1.1 23B81 darwin-arm64
    • Chrome (web)                    • chrome                                   • web-javascript • Google Chrome 130.0.6723.70
    ! Error: Browsing on the local area network for Tenna’s iPad (2). Ensure the device is unlocked and attached with a cable or associated with the same local
      area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for Sota’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area
      network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

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

• No issues found!
@ChurikiTenna ChurikiTenna changed the title 'value != null': is not true. syncfusion_flutter_charts 27.1.56 error 'value != null': is not true. Oct 29, 2024
@LavanyaGowtham2021 LavanyaGowtham2021 added charts Charts component open Open labels Oct 29, 2024
@Baranibharathip
Copy link

Hi @ChurikiTenna,

We have reviewed the issue and we would like to let you know that when you are setting the yAxisName on the series without assigning the same name to the corresponding primaryYAxis causes a null value assertion. This happens because the series is trying to link to an undefined axis.

To avoid this issue, we recommend assigning the same name to both the name property in primaryYAxis and the yAxisName property in the series. Please refer to the following code snippet.

Code snippet:

// Define name for the y axis.
   primaryYAxis: NumericAxis(
     name: "体重", // This name matches the yAxisName in the series
     ....

// Use the axis in the series
   return LineSeries<GraphData, String>(
     yAxisName: "体重",
     .... 

For more details, refer the following User Guide link:
UG: https://help.syncfusion.com/flutter/cartesian-charts/axis-customization#multiple-axes

Regards,
Baranibharathi P.

@LavanyaGowtham2021 LavanyaGowtham2021 added waiting for customer response Cannot make further progress until the customer responds. and removed open Open labels Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
charts Charts component waiting for customer response Cannot make further progress until the customer responds.
Projects
None yet
Development

No branches or pull requests

3 participants