Carter
Carter

Reputation: 179

How to add a dollar sign before displaying list data?

I need to display a dollar sign before an int. I tried to add it and escape from it but it displays an error. In the last Text() Widget it needs to be added before locations[index].amount.toString(). How would I properly do this?

      body: Container(
        child: ListView.builder(
          itemCount: locations.length,
          shrinkWrap: true,
          itemBuilder: (context, index) {
            return Padding(
              padding: EdgeInsets.symmetric(vertical: 1.0, horizontal: 4.0),
              child: Card(
                color: (index % 2 == 0) ? greycolor : Colors.white,
                child: Container(
                    height: 60,
                    padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text(locations[index].date,
                            style: TextStyle(fontSize: 20),
                            textAlign: TextAlign.left),
                        Container(
                            margin: EdgeInsets.only(right: 112),
                            child: Text(locations[index].location,
                                style: TextStyle(
                                    fontSize: 20, fontWeight: FontWeight.bold),
                                textAlign: TextAlign.center)),
                        Text(locations[index].amount.toString(),
                            style: TextStyle(fontSize: 20),
                            textAlign: TextAlign.right)
                      ],
                    )),
              ),
            );
          },
        ),

Upvotes: 0

Views: 146

Answers (1)

timilehinjegede
timilehinjegede

Reputation: 14033

This works:

   Text(
      '\$${locations[index].amount}',
      style: TextStyle(fontSize: 20),
      textAlign: TextAlign.right,
    );

Upvotes: 1

Related Questions