Home > Net >  Center Widget in Transform.translate
Center Widget in Transform.translate

Time:04-12

How can I position a Widget in the center of a Transform.translate?

That is MyWidget size/2 at the point - so that the widget's center is at the point Offset(100, 100)

return Transform.translate(
  offset: Offset(100, 100),
  child: const MyWidget());
}

CodePudding user response:

You can mix and match [Positioned] and [FractionalTranslation]. If you combine the two with a code like :

Positioned(
left: childWidget.x,
top: childWidget.y,
child: FractionalTranslation(
    translation: Offset(-0.5, -0.5),
    child: childWidget,
));

1

CodePudding user response:

Container(
  width: 200,
  height: 200,
  alignment: Alignment.center,
  child: const MyWidget())

Might have the desired effect, though it will come with empty space around it

  • Related