Flutter 在通过构造函数传递计算出的double以及再次设置状态以在flift中运行UI方面存在问题

Flutter 在通过构造函数传递计算出的double以及再次设置状态以在flift中运行UI方面存在问题,flutter,setstate,Flutter,Setstate,我开发了一个简单的FD计算器应用程序,在您输入基本详细信息后生成金额,我有一个饼图类,我想在单击calculate按钮时触发它,但由于某些原因,代码只运行一个,它只接受构造函数的参数,并且始终保持不变,这是一个动画饼图,我已经发布了两个类,一个是主屏幕,另一个是动画饼图,我是新手,所以如果你能帮我用我的计算按钮完全控制饼图状态,那将是很大的帮助,谢谢 图表代码 class _PieChartState extends State<PieChart> { final

我开发了一个简单的FD计算器应用程序,在您输入基本详细信息后生成金额,我有一个饼图类,我想在单击calculate按钮时触发它,但由于某些原因,代码只运行一个,它只接受构造函数的参数,并且始终保持不变,这是一个动画饼图,我已经发布了两个类,一个是主屏幕,另一个是动画饼图,我是新手,所以如果你能帮我用我的计算按钮完全控制饼图状态,那将是很大的帮助,谢谢

图表代码


class _PieChartState extends State<PieChart> {
         final double interestPercentage;
        final double principalPercentage;
         _PieChartState({this.interestPercentage,this.principalPercentage});
         Task task;
         List<charts.Series<Task,String>>_seriesPieData;
         _generateData(){
           setState(() {
             var pieData=[
               Task(task:'Principle',taskValue:interestPercentage,taskColor:Color(0xFF00897B),),
               Task(task:'Interest',taskValue:principalPercentage,taskColor:Color(0xff7FC4F4),),
             ];
             _seriesPieData.add(
               charts.Series(
                 data: pieData,
                 domainFn: (Task task,__)=>task.task,
                 measureFn: (Task task,__)=>task.taskValue,
                 colorFn: (Task task,__)=> charts.ColorUtil.fromDartColor(task.taskColor),
                 id: 'Fd Interest',
                 labelAccessorFn:(Task row,_)=>'${row.taskValue}\%',
               ),
             );
           });
       
         }
         @override
         void initState() {
           super.initState();
             _seriesPieData=List<charts.Series<Task,String>>();
             _generateData();
       
         }
         @override
         Widget build(BuildContext context) {
           return  Container(
             child:Expanded(
               child: charts.PieChart(
                   _seriesPieData,
                   animate: true,
                   animationDuration: Duration(seconds: 1),
                   defaultRenderer: new charts.ArcRendererConfig(
                       arcWidth: 110,
                       arcRendererDecorators: [
                         new charts.ArcLabelDecorator(
                             labelPosition: charts.ArcLabelPosition.inside)
                       ])),
             ) ,
           );
         }
       }
       
       class Task{
         String task;
         double taskValue;
         Color taskColor;
         Task({this.task,this.taskColor,this.taskValue});
       }
                  child: FlatButton(
                        height: 50,
                        shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(26))),
                        onPressed: (){
                          switch(animationController.status){
                            case AnimationStatus.completed:
                              animationController.reset();
                              animationController.forward();
                              break;
                            case AnimationStatus.dismissed:
                              animationController.forward();
                              break;
                          }
                          setState(() {
                            _checker=true;
                            this.answer=calculate();
                            this.finiteInterest=finalInterest();
                            this.interestPercentage=percentageThrower();
                            this.principalPercentage=100-this.interestPercentage;
                          });
        
                        }, child: Text('Calculate',style: TextStyle(color: Colors.white),)
                    ),
                  ),
                  Container(
                    decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        boxShadow: [
                          BoxShadow(
                            color:  Colors.blue.withOpacity(0.7),
                            offset: Offset(5,5),
                            spreadRadius: 2,
                            blurRadius: 8,
                          ),
                          BoxShadow(
                            color: Colors.blue.withOpacity(0.0),
                            offset: Offset(-5,-5),
                            spreadRadius: 2,
                            blurRadius:8,
                          )
                        ]
                    ),
                    margin: EdgeInsets.only(left: 15),
                    child: CircleAvatar(
                      child: Builder(
                        builder: (context){
                          if(_checker== true){
                            return Center(child: PieChart(interestPercentage:interestPercentage,principalPercentage:principalPercentage));}else{
                            return Container(color: Colors.white,width: 10,height: 10,);}},
                      ),
                      radius: 110,
                      backgroundColor: Colors.white,
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(top:30,left: 100),
                    child:SlideTransition(
                      position:tween,
                      child: FadeTransition(
                          opacity: animationController,
                          child: Container(
                            child: Container(
                              padding: EdgeInsets.all(12),
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: [
                                  answer_childs(text: "Principle ${totalAmount.text} ",colors: Colors.teal.shade600,),
                                  answer_childs(text: "Interest $finiteInterest",colors: Colors.lightBlue,),
                                  answer_childs(text:"Total Amount $answer",colors: Colors.black,),
                                ],
                              ),
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.only(topLeft:Radius.circular(18),bottomLeft:Radius.circular(18) ),
                              ),
                            ),
                            width: 350,
                            height: 100,
                            color: Colors.blue.withOpacity(0.0),
                          )
                      ),
                    ),
                  ),
                ],
              ),
            );
          }
          String calculate(){
            double amount;
            double principal;
            int termN;
            double interestN;
            principal= double.parse(totalAmount.text);
            termN= int.parse(term.text);
            interestN=double.parse(interest.text);
            amount = principal*(pow(1+(interestN/100), termN));
            amount=amount-amount%1;
            return '$amount';
          }
          double finalInterest(){
            double amount;double principal;int termN;  double finalInterest;double interestN;
            principal= double.parse(totalAmount.text);
            termN= int.parse(term.text);
            interestN=double.parse(interest.text);
            amount = principal*(pow(1+(interestN/100), termN));
            amount=amount-amount%1;
            finalInterest=amount-principal;
            finalInterest=finalInterest-finalInterest%1;
            return finalInterest;
          }
          double percentageThrower(){
            double interestPercentage;double principal;
            principal= double.parse(totalAmount.text);
            interestPercentage=finalInterest();
            interestPercentage=(interestPercentage/principal)*100;
            return interestPercentage;
          }
        }
还有一些我用来生成fd百分比和利息的函数,以便在Piechart上添加为标签,如果有人能帮助我使用Calculate FlatButton完全或主要更改Piechart上的百分比值,那将是一个很大的帮助 谢谢