Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Error with basic chart #45

Closed
ateodor1 opened this issue Apr 17, 2018 · 2 comments
Closed

Error with basic chart #45

ateodor1 opened this issue Apr 17, 2018 · 2 comments

Comments

@ateodor1
Copy link

Hi, I have this code that I copied from the example but it does not work, even with the version 0.2.0. Could you please check if it is a bug or I'm doing something wrong. Thanks.

I/flutter (23766): FlutterError.onError caught an errorThe WidgetLayoutDelegate custom multichild layout delegate forgot to lay out the following child:
I/flutter (23766): chartContainer: RenderErrorBox#5b0e9 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (23766): Each child must be laid out exactly once.
I/flutter (23766): Caught error: type '(Resultado, int) => String' is not a subtype of type '(dynamic, int) => String'

import 'package:condo/firebase/firestore.dart';
import 'package:condo/model/enquete.dart';
import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;

class Resultado {
final String alternativa;
final int quantidade;
final charts.Color color;

Resultado(this.alternativa, this.quantidade, Color color)
  : this.color = new charts.Color(
        r: color.red, g: color.green, b: color.blue, a: color.alpha);

}

class ResultadoEnquete extends StatefulWidget {
ResultadoEnquete(this.enquete, {Key key}) : super(key: key);
final Enquete enquete;

@OverRide
_ResultadoEnqueteState createState() => new _ResultadoEnqueteState();
}

class _ResultadoEnqueteState extends State {
List respostas = new List();

@OverRide
void initState() {
super.initState();
FirestoreUtil
.obterRespostasEnquete(widget.enquete.idCondominio, widget.enquete.id)
.snapshots
.map((_respostas) {
_respostas.documents.forEach((_resposta) {
RespostaEnquete resposta = new RespostaEnquete.fromMap(_resposta.data);
respostas.add(resposta);
});
});
}

@OverRide
Widget build(BuildContext context) {

List<Resultado> data = [
  new Resultado('1', 12, Colors.red),
  new Resultado('2', 42, Colors.yellow),
  new Resultado('3', 15, Colors.green),
];

List<charts.Series<Resultado, String>> series = [
  new charts.Series<Resultado, String>(
    id: 'Clicks',
    domainFn: (Resultado clickData, _) => clickData.alternativa,
    measureFn: (Resultado clickData, _) => clickData.quantidade,
    colorFn: (Resultado clickData, _) => clickData.color,
    data: data,
  ),
];

charts.BarChart chart = new charts.BarChart(series, animate: false);
var chartWidget = new Container(
  height: 200.0,
    child: chart,
);

return new Scaffold(
  appBar: new AppBar(
    title: new Text('Resultado da Enquete'),
  ),
  body: new Center(
    child: new Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        new Text(
          'Relatorio',
        ),
        chartWidget,
      ],
    ),
  ),
);

}

}

@lorrainekan
Copy link
Contributor

new BarChart needs to be new BarChart< Resultado> because of Dart2 fixes.

Please see https://google.github.io/charts/flutter/gallery.html for the latest examples.

@AlexanderBrese
Copy link

AlexanderBrese commented Apr 18, 2018

Code

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

class BarCounter {
  final int domain;
  final int measure;
  final charts.Color color;

  BarCounter(this.domain, this.measure, Color color)
      : this.color = new charts.Color(
            r: color.red, g: color.green, b: color.blue, a: color.alpha);
}

class Statistics {
  Statistics(
      this.trackAmount,
      this.barAmount,
      this.lastTrackDate,
      this.barCounters,
      this.tracksMonthly,
      this.tracksDaily,
      this.speedCounters);

  int trackAmount;
  int barAmount;
  DateTime lastTrackDate;
  List<BarCounter> barCounters;
  List<int> tracksMonthly;
  List<int> tracksDaily;
  List<int> speedCounters;
}

class BarCounterChart extends StatelessWidget {
  final List<charts.Series> seriesList;
  final bool animate;

  BarCounterChart(List<BarCounter> barCounters, {this.animate})
      : this.seriesList = [
          new charts.Series<BarCounter, int>(
            id: 'BarCounter',
            domainFn: (BarCounter barCounter, _) => barCounter.domain,
            measureFn: (BarCounter barCounter, _) => barCounter.measure,
            colorFn: (BarCounter barCounter, _) => barCounter.color,
            data: barCounters,
          ),
        ];

  @override
  Widget build(BuildContext context) {
    return new charts.PieChart<BarCounter, int>(seriesList, animate: animate);
  }
}

Error message
Another exception was thrown: type '(BarCounter, int) => int' is not a subtype of type '(dynamic, int) => dynamic'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants