Flutter - Set Text in new line

2,558

Solution 1

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

Solution 2

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,
  ),
 ),
)
Share:
2,558
Mehrdad Hosseini
Author by

Mehrdad Hosseini

Updated on December 17, 2022

Comments

  • Mehrdad Hosseini
    Mehrdad Hosseini 11 months

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

    }

    • Peter Haddad
      Peter Haddad almost 4 years
      Isn't the subtitle on a new line?
  • Federick Jonathan
    Federick Jonathan almost 4 years
    @MehrdadHosseini You can mark the answer as correct so people coming here know the question has a correct answer