Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 按对话框中的按钮时文本不更新_Flutter_Dart - Fatal编程技术网

Flutter 按对话框中的按钮时文本不更新

Flutter 按对话框中的按钮时文本不更新,flutter,dart,Flutter,Dart,我有一个文本小部件和两个按钮来增加或减少计数按钮增加计数,按钮-减少计数。计数显示在文本小部件中。调试时,计数正在更改,但文本没有更新。也没有得到任何错误。如何做到这一点。这是我的密码: _showDetails(BuildContext context, String barcodeResult) { return showDialog( context: context, barrierDismissible: true, builder: (BuildCont

我有一个文本小部件和两个按钮来增加或减少计数按钮增加计数,按钮-减少计数。计数显示在文本小部件中。调试时,计数正在更改,但文本没有更新。也没有得到任何错误。如何做到这一点。这是我的密码:

  _showDetails(BuildContext context, String barcodeResult) {

return showDialog(
    context: context,
    barrierDismissible: true,
    builder: (BuildContext context) {
      return Dialog(
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10.0)),
        child: Container(
          height: 350.0,
          width: 200.0,
          decoration:
              BoxDecoration(borderRadius: BorderRadius.circular(20.0)),
          child: Column(
            children: <Widget>[
              Stack(
                children: <Widget>[
                  Container(
                    height: 150.0,
                  ),
                  Container(
                    height: 100.0,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(10.0),
                          topRight: Radius.circular(10.0),
                        ),
                        color: Colors.teal),
                  ),
                  Positioned(
                    top: 50.0,
                    left: 94.0,
                    child: Container(
                      height: 90.0,
                      width: 90.0,
                      child: CircleAvatar(
                        ExactAssetImage(
                                'assets/images/user-image-default.png'),
                      ),

                    ),
                  )
                ],
              ),
              SizedBox(
                height: 20.0,
              ),
              Padding(
                padding: EdgeInsets.all(10.0),
                child: Text(
                  name,
                  style: TextStyle(
                      fontSize: 14.0, fontWeight: FontWeight.w300),
                ),
              ),
              Padding(
                padding: EdgeInsets.all(10.0),
                child: Text(
                  description,
                  style: TextStyle(
                      fontSize: 14.0, fontWeight: FontWeight.w300),
                ),
              ),
              Padding(
                padding: EdgeInsets.all(10.0),
                child: Text(
                  'Price : $price',
                  style: TextStyle(
                      fontSize: 14.0, fontWeight: FontWeight.w300),
                ),
              ),
              SizedBox(
                height: 15.0,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  ClipOval(
                    child: Material(
                      color: Colors.teal, // button color
                      child: InkWell(
                        //splashColor: Colors.red, // inkwell color
                        child: SizedBox(
                            width: 40,
                            height: 40,
                            child: Icon(
                              Icons.add,
                              color: Colors.white,
                            )),
                        onTap: () {
                          setState(() {
                            // count++;
                            count = count + 1;
                            print(count);
                          });
                        },
                      ),
                    ),
                  ),
                  SizedBox(
                    width: 20,
                  ),
                  Text(count.toString()),

                  SizedBox(
                    width: 20,
                  ),
                  ClipOval(
                    child: Material(
                      color: Colors.teal, // button color
                      child: InkWell(
                        //  splashColor: Colors.red, // inkwell color
                        child: SizedBox(
                            width: 40,
                            height: 40,
                            child: Icon(
                              Icons.remove,
                              color: Colors.white,
                            )),
                        onTap: () {
                          setState(() {
                            //count--;
                            count = count - 1;
                            print(count);
                          });
                        },
                      ),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      );
    });
  }
\u showDetails(构建上下文上下文、字符串barcodeResult){
返回显示对话框(
上下文:上下文,
是的,
生成器:(BuildContext上下文){
返回对话框(
形状:圆形矩形边框(
边界半径:边界半径。圆形(10.0)),
子:容器(
高度:350.0,
宽度:200.0,
装饰:
盒子装饰(边框半径:边框半径。圆形(20.0)),
子:列(
儿童:[
堆叠(
儿童:[
容器(
高度:150.0,
),
容器(
高度:100.0,
装饰:盒子装饰(
borderRadius:仅限borderRadius(
左上:半径。圆形(10.0),
右上角:半径。圆形(10.0),
),
颜色:颜色。青色),
),
定位(
排名:50.0,
左:94.0,
子:容器(
身高:90.0,
宽度:90.0,
孩子:圆环星(
精确估计(
“资产/图像/用户图像默认值.png”),
),
),
)
],
),
大小盒子(
身高:20.0,
),
填充物(
填充:所有边缘设置(10.0),
子:文本(
名称
样式:TextStyle(
fontSize:14.0,fontWeight:fontWeight.w300),
),
),
填充物(
填充:所有边缘设置(10.0),
子:文本(
描述
样式:TextStyle(
fontSize:14.0,fontWeight:fontWeight.w300),
),
),
填充物(
填充:所有边缘设置(10.0),
子:文本(
“价格:$Price”,
样式:TextStyle(
fontSize:14.0,fontWeight:fontWeight.w300),
),
),
大小盒子(
身高:15.0,
),
划船(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
斜坡(
儿童:材料(
颜色:Colors.teal,//按钮颜色
孩子:InkWell(
//splashColor:Colors.red,//墨水池颜色
孩子:大小盒子(
宽度:40,
身高:40,
子:图标(
Icons.add,
颜色:颜色,白色,
)),
onTap:(){
设置状态(){
//计数++;
计数=计数+1;
打印(计数);
});
},
),
),
),
大小盒子(
宽度:20,
),
文本(count.toString()),
大小盒子(
宽度:20,
),
斜坡(
儿童:材料(
颜色:Colors.teal,//按钮颜色
孩子:InkWell(
//splashColor:Colors.red,//墨水池颜色
孩子:大小盒子(
宽度:40,
身高:40,
子:图标(
图标。删除,
颜色:颜色,白色,
)),
onTap:(){
设置状态(){
//计数--;
计数=计数-1;
打印(计数);
});
},
),
),
),
],
),
],
),
),
);
});
}

屏幕截图:


这是工作代码

_showDetails(BuildContext context, String barcodeResult) {
  return showDialog(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return StatefulBuilder(builder: (context, setState) {
          return Dialog(
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
            child: Container(
              height: 350.0,
              width: 200.0,
              decoration: BoxDecoration(borderRadius: BorderRadius.circular(20.0)),
              child: Column(
                children: <Widget>[
                  Stack(
                    children: <Widget>[
                      Container(
                        height: 150.0,
                      ),
                      Container(
                        height: 100.0,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                              topLeft: Radius.circular(10.0),
                              topRight: Radius.circular(10.0),
                            ),
                            color: Colors.teal),
                      ),
                      Positioned(
                        top: 50.0,
                        left: 94.0,
                        child: Container(
                          height: 90.0,
                          width: 90.0,
                          child: CircleAvatar(
                            backgroundImage: ExactAssetImage(chocolateImage),
                          ),
                        ),
                      )
                    ],
                  ),
                  SizedBox(
                    height: 20.0,
                  ),
                  Padding(
                    padding: EdgeInsets.all(10.0),
                    child: Text(
                      name,
                      style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w300),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(10.0),
                    child: Text(
                      description,
                      style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w300),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(10.0),
                    child: Text(
                      'Price : \$${price * count}',
                      style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w300),
                    ),
                  ),
                  SizedBox(
                    height: 15.0,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      ClipOval(
                        child: Material(
                          color: Colors.teal, // button color
                          child: InkWell(
                            //splashColor: Colors.red, // inkwell color
                            child: SizedBox(
                                width: 40,
                                height: 40,
                                child: Icon(
                                  Icons.add,
                                  color: Colors.white,
                                )),
                            onTap: () {
                              setState(() {
                                // count++;
                                count = count + 1;
                                print(count);
                              });
                            },
                          ),
                        ),
                      ),
                      SizedBox(
                        width: 20,
                      ),
                      Text(count.toString()),
                      SizedBox(
                        width: 20,
                      ),
                      ClipOval(
                        child: Material(
                          color: Colors.teal, // button color
                          child: InkWell(
                            //  splashColor: Colors.red, // inkwell color
                            child: SizedBox(
                                width: 40,
                                height: 40,
                                child: Icon(
                                  Icons.remove,
                                  color: Colors.white,
                                )),
                            onTap: () {
                              setState(() {
                                //count--;
                                count = count - 1;
                                print(count);
                              });
                            },
                          ),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          );
        });
      });
}
\u showDetails(构建上下文上下文、字符串barcodeResult){
返回显示对话框(
上下文:上下文,
是的,
生成器:(BuildContext上下文){
返回StatefulBuilder(生成器:(上下文,设置状态){
返回对话框(
形状:RoundedRectangleBorder(borderRadius:borderRadius.circular(10.0)),
子:容器(
高度:350.0,
宽度:200.0,
装饰:盒子装饰(边框半径:边框半径。圆形(20.0)),
子:列(
儿童:[
堆叠(
儿童:[
容器(
高度:150.0,
),
容器(
高度:100.0,
装饰:盒子装饰(
borderRadius:仅限borderRadius(
左上:半径。圆形(10.0),