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,
)
>Solution :
Positioned Widget
child widgetcan 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 widgetcan be translated by a certain amount using theoffsetattribute 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:
- Positioned: https://api.flutter.dev/flutter/widgets/Positioned-class.html
- Transform.translate: https://api.flutter.dev/flutter/widgets/Transform-class.html