'Flutter screen rotation triggers overflow

Description : the issue I'am facing is that when I force rotate my screen in Flutter it does paint the layout and THEN rotate the screen. So before the rotation flutter show an overflow bar for some of the widgets (especially when I come back from the screen but it happens also when pushing a new one).
Initially I force the screen to be landscape. Then I rotate it for some menu. Once it is done I just come back to portrait using Navigator.pop(context)
Here is a video of the issue where I slowed down the important fragment : Video of the issue

Here is my code sample:

class ScreenRotator extends StatefulWidget {
  const ScreenRotator({
    Key? key,
    required this.child,
  }) : super(key: key);

  final Widget child;

  @override
  State<ScreenRotator> createState() => _ScreenRotatorState();
}

class _ScreenRotatorState extends State<ScreenRotator> {
  @override
  void initState() {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
    ]);
    super.initState();
  }

  @override
  dispose() {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return widget.child;
  }
}

Some points about my code :

  • Refering to the screen rotation it does need te be inside a StateFull widget (calling initState() and dispose() where the screen rotation happens).
  • I made a special widget called ScreenRotator which calls a StateLess widget (the screen layout).

I couldn't find anything linked to my question and this question refers to older ones which are the following :
Flutter: how to prevent device orientation changes and force portrait?
How to force the application to Portrait mode in flutter

Note : There is a problem with my buttons (TextButtons) but this is not the actual issue i'm asking help for.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source