Я использую круговую диаграмму, где значение int исходит от огненной бури.На круговой диаграмме значение int
скрыто до double
, но из-за запоздалого поступления данных из хранилища пожарных данных выдает ошибку (метод toDouble
был вызван при null
. Получатель: null Пробный вызов: toDouble()
) в течение одной секунды я использую приведенный ниже код.
для получения
@override
void initState() {
// TODO: implement initState
super.initState();
subscription = Firestore.instance.document("users/${widget.userid}").snapshots().listen((datasnapshot) {
if (datasnapshot.data.containsKey(widget.alllist.title)) {
setState(() {
userscoren = datasnapshot.data[widget.alllist.title];
});
} else if (!datasnapshot.data.containsKey(widget.alllist.title)) {
setState(() {
userscoren = 0;
});
}
});
}
на круговой диаграмме
List<CircularStackEntry>_generateChartData(int stage){
Color dialColor = Colors.green;
labelcolor = dialColor;
List<CircularStackEntry>data=[
new CircularStackEntry([new CircularSegmentEntry(stage.toDouble(), dialColor,)])
];
return data;
}
в виджете
@override
Widget build(BuildContext context) {
// TODO: implement build
return widget.intp==0?
InkWell(
child: Card(
child: Stack(
children: <Widget>[
Padding(padding: EdgeInsets.all(7.0),
child: new Container(
child: new AnimatedCircularChart(
key: _chartKey,
size: _chartSize,
initialChartData:_generateChartData(userscoren),
chartType: CircularChartType.Radial,
edgeStyle: SegmentEdgeStyle.round,
percentageValues: true,
holeRadius: 38.0,
),
width: 80.0,
height: 80.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.blue,width: 1.0,style: BorderStyle.solid,),
image: new DecorationImage(
fit: BoxFit.fill,
image: new NetworkImage(
widget.alllist.imageUrl)),
),
margin: const EdgeInsets.symmetric(horizontal: 20.0),
// child: Text(name),
),),
Positioned(child:Center(
child: Text(widget.alllist.title,style: TextStyle(fontWeight: FontWeight.bold,color: Colors.blueGrey),)),
bottom: 1.0,left: 20.0,right: 20.0,top: 85.0,
),
// Padding(padding: EdgeInsets.only(top: 80.0,left: 10.0),
// child: Text(alllist.title,style: TextStyle(fontWeight: FontWeight.bold,color: Colors.blueGrey),),
// ),
],
),
),
onTap: (){
if(widget.alllist.topictype =="Description&Question"){
Navigator.of(context).push(new MaterialPageRoute(builder: (context)=>new DisAndQuesShow(alllist: widget.alllist,userid: widget.userid,)));
}else{
if(widget.alllist.topictype=="Description"){
Navigator.of(context).push(new MaterialPageRoute(builder: (context)=>new Discribtion(alllist: widget.alllist,)));
}
}
},
)