0

我有一张卡片和一个容器。在卡片里面,我有一个容器,容器有行和列。在最后一列,我有一个从卡上溢出的按钮。

请检查图像,我的代码逻辑太多,这就是为什么我无法分享我的完整代码。这对任何人来说都太难理解了。

图片

这是我的代码:

Spacer(),
 Container(

                        child: RaisedButton(

                          color: MyColors.primaryColor,
                          child: subonoff(subcatextraproduct[index]) && visbutton ? Text("   Get Once   ",style: TextStyle(color: Colors.white,fontSize: 10)) : Text("+ Add to Cart",style: TextStyle(color: Colors.white,fontSize: 10)),
                          onPressed: (){
                            subtotal=subtotal+subcatextraproduct[index].price.round();
                            grandtotal=subtotal+deliverycharges;
                            setState(() {
                              //change="Once";
                              // print("sum setstate");
                              // sum++;
                              myfunc();
                              //this.widget.callback(sum);

                            });
                            makefalsbutton(subcatextraproduct[index].id);
                            maketruecountr(subcatextraproduct[index].id);
                            totalcsetone(subcatextraproduct[index].id);
                          //  print("i am in add");
                          },
                        ),
                      ),
4

3 回答 3

0

您不应该在Container没有任何属性的情况下使用子元素,并且不要使用函数来制作小部件

至于你的问题——试着把你的按钮包装成Expanded

我建议您阅读这篇文章https://flutter.dev/docs/development/ui/layout/constraints

试试这个代码:

class ProductRow extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Row(
        children: [
          Expanded(
            child: Image.network(
              'https://i.stack.imgur.com/vYOjL.png',
              fit: BoxFit.contain,
            ),
          ),
          Expanded(
            child: Column(
              children: [
                Text('Yougurt'),
                Text('1 kg'),
                Text('9% OFF'),
                Text('RS 110.0'),
              ],
            ),
          ),
          RaisedButton.icon(
            icon: const Icon(Icons.add),
            label: const Text('Add to cart'),
            onPressed: () {},
          )
        ],
      ),
    );
  }
}
于 2020-07-30T21:45:38.320 回答
0

尝试

RaisedButton(
      onPressed: ...,
      child: FittedBox(
        child: Text(
          condition ? "Get Once" : "Add to cart",
          style: TextStyle(color: Colors.white, fontSize: 10),
        ),
      ),
    )

或者

[
 Spacer(),
 Flexible(child: RaisedButton()),
 ...
]
于 2020-07-31T09:10:48.397 回答
0

2条建议:

  1. 移除容器
  2. 如果您无法删除容器,请将其替换为Flexible小部件。放fit: FlexFit.loose
于 2020-07-30T22:11:58.147 回答