簡體   English   中英

Flutter - 在新行中設置文本

[英]Flutter - Set Text in new line

我是 flutter 的新手,現在我正在設計一個應用程序

但在這部分項目中,我想在標題下方的新行中設置價格,我在這里尋找類似的問題,但我無法解決

這是代碼:

Widget build(BuildContext context) {
return Card(
  child: Hero(
      tag: prod_name,
      child: Material(
        child: InkWell(
          onTap: () {},
          child: GridTile(
              footer: Container(
                color: Colors.white,
                child: ListTile(
                  leading: Text(
                    prod_name,
                    textAlign: TextAlign.left,
                    style: TextStyle(color: Colors.grey, fontSize: 12),
                  ),
                  title: Text("\$$prod_old_price"),
                  subtitle: Text(
                    "\$$prod_price",
                    style: TextStyle(fontWeight: FontWeight.w800,),
                  ),
                ),
              ),
              child: Image.asset(
                prod_pic,
                fit: BoxFit.fitHeight,
              )),
        ),
      )),
);

}

@Mehrdad Hosseini,您必須將一列有兩個孩子的卡片作為副標題,並將兩個文本小部件作為兩個孩子。 請在您的代碼中進行以下更改。

 @override
  Widget build(BuildContext context) {
    return Card(
      child: Hero(
          tag: prod_name,
          child: Material(
            child: InkWell(
              onTap: () {},
              child: GridTile(
                  footer: Container(
                    color: Colors.white,
                    child: ListTile(
                      title: Text(
                        prod_name,
                        textAlign: TextAlign.left,
                        style: TextStyle(color: Colors.grey, fontSize: 12),
                      ),
                      subtitle: Column(
                        children: <Widget>[
                          Text("\$$prod_old_price"),
                          Text(
                            "\$$prod_price",
                            style: TextStyle(fontWeight: FontWeight.w800,),
                          ),
                        ],
                      ),
                    ),
                  ),
                  child: Image.asset(
                    prod_pic,
                    fit: BoxFit.fitHeight,
                  )),
            ),
          )),
    );
  }

這是你想要達到的目標嗎?

在此處輸入圖片說明

ListTile(
 title: Text('$prod_name'),
 subtitle: Text(
  '''\$$old_price\n\$$prod_price''',
  style: TextStyle(
   fontWeight: FontWeight.w800,
  ),
 ),
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM