Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Set Text in new line

I am new in flutter , and now I'm working on design an application

but in this part of project I want to set price in new line below the title , I have looking for similar question here but I can't solve it

Here is code:

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,
              )),
        ),
      )),
);

}

like image 906
Mehrdad Hosseini Avatar asked Feb 23 '26 19:02

Mehrdad Hosseini


2 Answers

@Mehrdad Hosseini, You have to take one column with two children for subtitle of card and give the two text widgets as two children. Please go through the below changes in your code.

 @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,
                  )),
            ),
          )),
    );
  }
like image 108
Dhaval Kansara Avatar answered Feb 26 '26 10:02

Dhaval Kansara


Is this what you are trying to achieve?

enter image description here

ListTile(
 title: Text('$prod_name'),
 subtitle: Text(
  '''\$$old_price\n\$$prod_price''',
  style: TextStyle(
   fontWeight: FontWeight.w800,
  ),
 ),
)
like image 28
Federick Jonathan Avatar answered Feb 26 '26 08:02

Federick Jonathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!