OrientationWidget constructor

const OrientationWidget({
  1. required Widget child,
  2. required List<DeviceOrientation> orientations,
  3. List<DeviceOrientation>? then,
  4. Key? key,
})

OrientationWidget is a widget that sets the orientation of the device. Should be used with MaterialPageRoute to set the orientation of the page.

then is called when the widget is disposed if not null. It is useful to restore the orientation to the previous one. For example, if you want to restore the orientation to portrait after the user leaves the landscape page.

Navigator.of(context).push(
  MaterialPageRoute(
    builder: (context) => const OrientationWidget(
      orientations: [DeviceOrientation.landscapeLeft],
      then: portraitOrientations,
      child: const PortraitPage(),
    ),
  ),
);

Implementation

const OrientationWidget({
  required this.child,
  required this.orientations,
  this.then,
  Key? key,
}) : super(key: key);