google / charts

https://pub.dev/packages/charts_flutter
Apache License 2.0
2.81k stars 1.22k forks source link

OrdinalComboChart and LineChart do not work in release mode, when placed inside MaterialApp (in v0.5 not in v0.4) #177

Open TomOerlemans opened 5 years ago

TomOerlemans commented 5 years ago

When using OrdinalComboChart or LineChart I noticed that they stop working when run in release mode and placed inside a MaterialApp widget. This is the error I get:

I/flutter (30490): The following RenderObject was being processed when the exception was fired:
I/flutter (30490):   ChartContainerRenderObject<String>#6aca1 NEEDS-PAINT
I/flutter (30490):   parentData: <none>
I/flutter (30490):   constraints: BoxConstraints(w=360.0, h=640.0)
I/flutter (30490):   semantic boundary
I/flutter (30490):   size: Size(0.0, 0.0)
I/flutter (30490): This RenderObject has no descendants.

And this is the code to reproduce the problem:

import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;

void main() {
  runApp(new OrdinalComboBarLineChart());
}

class OrdinalComboBarLineChart extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<charts.Series> seriesList = _createSampleData();

    return MaterialApp(
        home: Container(
            height: 205.0,
            width: 350.0,
            child: charts.OrdinalComboChart(seriesList,
                animate: false,
                defaultRenderer: charts.LineRendererConfig(
                    areaOpacity: 0.8, includeArea: true),
                customSeriesRenderers: [
                  new charts.LineRendererConfig(customRendererId: 'LineOne'),
                ])));
  }

  /// Create series list with multiple series
  List<charts.Series<OrdinalSales, String>> _createSampleData() {
    var categoryOne = [
      new OrdinalSales('0:00', 0),
      new OrdinalSales('12:00', 0),
      new OrdinalSales('23:59', 25),
    ];

    var lineOne = [
      new OrdinalSales('0:00', 30),
      new OrdinalSales('12:00', 15),
      new OrdinalSales('23:59', 7),
    ];

    final Color myRed = const Color(0xFFEB4141);
    final Color myDarkBackground = const Color(0xFF101926);

    return [
      new charts.Series<OrdinalSales, String>(
          id: 'CategoryOne',
          colorFn: (_, __) => charts.Color(
              r: myRed.red, g: myRed.green, b: myRed.blue, a: myRed.alpha),
          domainFn: (OrdinalSales sales, _) => sales.year,
          measureFn: (OrdinalSales sales, _) => sales.sales,
          data: categoryOne),
      new charts.Series<OrdinalSales, String>(
          id: 'LineOne ',
          colorFn: (_, __) => charts.Color(
              r: myDarkBackground.red,
              g: myDarkBackground.green,
              b: myDarkBackground.blue,
              a: myDarkBackground.alpha),
          domainFn: (OrdinalSales sales, _) => sales.year,
          measureFn: (OrdinalSales sales, _) => sales.sales,
          data: lineOne)
        ..setAttribute(charts.rendererIdKey, 'LineOne'),
    ];
  }
}

/// Sample ordinal data type.
class OrdinalSales {
  final String year;
  final int sales;
  OrdinalSales(this.year, this.sales);
}

I am using charts_flutter: ^0.5.0.

TomOerlemans commented 5 years ago

So I am far from a great programmer (and thus I don't really understand what is going on), but I just discovered that this issue does not exist when I use charts_flutter: ^0.4.0, as opposed to charts_flutter: ^0.5.0. So it seems like the issue got introduced with the latest update.