I need a Lottie to be fitted to the whole screen, so I set Lottie height and width to double.infinity.
But the Lottie getting expanded from top left corner instead of from centre making the centre of lottie slightly moved to the right bottom direction, No matter the alignment. Also tried wrapping in Center and Align
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Lottie.asset(
'splash_logo.json',
alignment: Alignment.center,
repeat: true,
height: double.infinity,
fit: BoxFit.cover,
width: double.infinity,
),
),
);
}
How to expand it keeping the centre of the Lottie at the Centre of the screen
You could try to wrap the Lottie animation in a
Containerand set the height and width of theContainertodouble.infinity. This will allow theContainerto fill the entire screen, and the animation will be centered within thisContainer.Example;
Another way is to use the
OverflowBoxwidget to allows its child to overflow the parent's box, which can help with alignment issues.Edit
You could also try the
Stackwidget which allow to stack multiple children widgets on top of each other.Example;
Also, I add this
Alignthat you've already use, maybe the approach here become different;If neither of these solutions work, it's possible that the issue here is the Lottie itself. The animation might have been created in a way that it's not centered. If so, you might need to recreate the animation or edit it.