flutter_radar_chart icon indicating copy to clipboard operation
flutter_radar_chart copied to clipboard

Can't use decimal values in Radar Chart

Open arielramos opened this issue 3 years ago • 0 comments

Hi, it seems that when I send Double variables the chart is not compiling well, is there something that I'm missing or it is kust that the library only receive int values?

// Automatic FlutterFlow imports import '../../backend/backend.dart'; import '../../flutter_flow/flutter_flow_theme.dart'; import '../../flutter_flow/flutter_flow_util.dart'; import '../widgets/index.dart'; // Imports other custom widgets import '../../flutter_flow/custom_functions.dart'; // Imports custom functions import 'package:flutter/material.dart'; // Begin custom widget code // DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:flutter_radar_chart/flutter_radar_chart.dart';

class Radar5Eses extends StatefulWidget { const Radar5Eses({ Key? key, this.width, this.height, required this.seiri, required this.seiton, required this.seiso, required this.seiketsu, required this.shitsuke, }) : super(key: key);

final double? width; final double? height; final double seiri; final double seiton; final double seiso; final double seiketsu; final double shitsuke;

@override _Radar5EsesState createState() => _Radar5EsesState(); }

class _Radar5EsesState extends State<Radar5Eses> { bool darkMode = false; bool useSides = false; double numberOfFeatures = 5; @override Widget build(BuildContext context) { const ticks = [5, 4, 3, 2, 1]; var features = ["SEIRI", "SEITON", "SEISO", "SEIKETSU", "SHITSUKE"]; var data = [ [ widget.seiri.round(), widget.seiton.round(), widget.seiso.round(), widget.seiketsu.round(), widget.shitsuke.round() ] ];

features = features.sublist(0, numberOfFeatures.floor());
data = data
    .map((graph) => graph.sublist(0, numberOfFeatures.floor()))
    .toList();

return Scaffold(
  appBar: AppBar(
    title: Text('Gráfico de Radar'),
  ),
  body: Container(
    color: darkMode ? Colors.black : Colors.white,
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 8.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              darkMode
                  ? Text(
                      'Modo claro',
                      style: TextStyle(color: Colors.white),
                    )
                  : Text(
                      'Modo oscuro',
                      style: TextStyle(color: Colors.black),
                    ),
              Switch(
                value: this.darkMode,
                onChanged: (value) {
                  setState(() {
                    darkMode = value;
                  });
                },
              ),
            ],
          ),
        ),
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 8.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              useSides
                  ? Text(
                      'Poligonal',
                      style: darkMode
                          ? TextStyle(color: Colors.white)
                          : TextStyle(color: Colors.black),
                    )
                  : Text(
                      'Circular',
                      style: darkMode
                          ? TextStyle(color: Colors.white)
                          : TextStyle(color: Colors.black),
                    ),
              Switch(
                value: this.useSides,
                onChanged: (value) {
                  setState(() {
                    useSides = value;
                  });
                },
              ),
            ],
          ),
        ),
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 8.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              Text(
                'Niveles',
                style: TextStyle(
                    color: darkMode ? Colors.white : Colors.black),
              ),
              Expanded(
                child: Slider(
                  value: this.numberOfFeatures,
                  min: 3,
                  max: 5,
                  divisions: 3,
                  onChanged: (value) {
                    setState(() {
                      numberOfFeatures = value;
                    });
                  },
                ),
              ),
            ],
          ),
        ),
        Expanded(
          child: darkMode
              ? RadarChart.dark(
                  ticks: ticks,
                  features: features,
                  data: data,
                  reverseAxis: true,
                  useSides: useSides,
                )
              : RadarChart.light(
                  ticks: ticks,
                  features: features,
                  data: data,
                  reverseAxis: true,
                  useSides: useSides,
                ),
        ),
      ],
    ),
  ),
);

} }

arielramos avatar Jan 04 '23 22:01 arielramos