0

I'm having an issue aligning a Row at the end of a card within a ListView.Builder. When I apply a mainAxisAlignment: MainAxisAlignment.end it doesn't go to right side of the card like I want. The distance right it goes varies on how long the data before it is. What Am I doing wrong? Any advice is welcome! Thanks!

This is what it looks like. I want the dollar amounts to be all the way to the right. enter image description here

Here is the code for the ListView.Builder

              return ListView.builder(
                itemCount: transaction.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,
                          child: Row(
                            children: <Widget>[
                              Expanded(
                                flex: 1,
                                child: Column(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Container(
                                    margin: EdgeInsets.only(left: 5, top: 13),
                                    child: AutoSizeText(transaction[index].date,
                                        maxLines: 1,
                                        style: TextStyle(
                                            fontSize: 14, color: Colors.black),
                                        textAlign: TextAlign.left),
                                  ),
                                ],
                              ),),
                              Flexible(
                                flex: 3,
                                child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Padding(
                                      padding: EdgeInsets.only(top: 13, left: 10),
                                      child: AutoSizeText(transaction[index].tester,
                                              maxLines: 1,
                                              style: TextStyle(
                                                  fontWeight: FontWeight.bold,
                                                  color: Colors.black,
                                                  fontFamily: 'Montserrat'),)
                                      ),
                                  Padding(
                                    padding: EdgeInsets.only(left: 10),
                                    child:
                                        AutoSizeText(
                                          '${transaction[index].test}',
                                          overflow: TextOverflow.ellipsis,
                                          style: TextStyle(
                                              color: Colors.black,
                                              fontStyle: FontStyle.italic),
                                        ),
                                  ),
                                ],
                              ),),
                              Flexible(
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  Padding(
                                    padding:
                                    EdgeInsets.only(top: 13),
                                    child: Container(
                                      child: Text(
                                          '\$${transaction[index].amount}',
                                          style: TextStyle(
                                              fontSize: 16,
                                              color: Colors.black),
                                          textAlign: TextAlign.right),
                                    ),
                                  ),
                                ],
                              ),)
                            ],
                          )),
                    ),
                  );
                },
              );
Carter
  • 179
  • 11

1 Answers1

0

just replace Flexible with Expanded

Flexible takes only the needed space, and Expanded takes all available space

see this To clarify more

I hope this is helpful

enter image description here