5

In my case, I have a Stack containing Icon and Card

I want the icon to appear in the right corner in case LTR and in the left corner in case RTL

I have the following code:

Stack(
      children: <Widget>[
        Card(
          color: Colors.white,
          elevation: 4,
          margin: EdgeInsets.only(top: 8, right: 8, left: 8),
          child: Container(
            height: 100,
            width: double.infinity,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text('text 1'),
                  Text('text 2'),
                  Text('text 3'),
                ],
              ),
            ),
          ),
        ),
        Positioned(
          top: 10,
          left: 10,
          child: Icon(
            Icons.ac_unit,
            size: 50,
          ),
        )
      ],
    );

The result in RTL mode is : enter image description here

The result in LTR mode is : enter image description here

How can I fix this

farouk osama
  • 2,374
  • 2
  • 12
  • 30

2 Answers2

12

try this

  Positioned.directional(textDirection:Directionality.of(context) ,
    top: 10,
    end:  10,
    child: Icon(
      Icons.ac_unit,
      size: 50,
    ),
  )
M Alkhatib
  • 627
  • 4
  • 12
-1

UPDATE

Put the icon inside a Container with maxWidth and set the alignment like below

alignment: isRTL? Alignment.centerLeft: Alignment.centerRight;

set the alignment property of Stack like this.

when the Language is changed to RTL just call

setState((){
 isRTL = true;
})

in a stateful widget.

vice versa if you want to change it to LTR

Yadu
  • 2,979
  • 2
  • 12
  • 27