Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Difference between Positioned and Transform.translate in Flutter?

Both can offset a widget. What should be used?

I used these inside a stack:

Transform.translate(
   offset: Offset(0.0,29),
   child: ElevatedButton(
             onPressed: (){},
             child: Text("Click me"),
          ),
)
Positioned(
   child: ElevatedButton(
             onPressed: (){},
             child: Text("Click me"),
   ),
   bottom: -29,
)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Positioned Widget

  • child widget can be positioned in relation to the stack.
  • you need to utilise the top, bottom, left, and right properties to specify the widget’s position when utilising the position property.

Transform.translate

  • child widget can be translated by a certain amount using the offset attribute which is used to define the amount of translation.

Depending on your use case, you may use one of these widgets in your sample code. Use Positioned if you wish to place the widget in relation to the stack. Use Transform.translate if you wish to translate the widget by a specific amount.

Further refer:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading