findCurrentOrientation method

Future<Orientation> findCurrentOrientation(
  1. BuildContext context
)

Implementation

Future<Orientation> findCurrentOrientation(BuildContext context) async {
  final completer = Completer<Orientation>();

  try {
    SchedulerBinding.instance.scheduleFrameCallback((_) {
      final orientation = MediaQuery.orientationOf(context);
      _logger.info('current orientation', orientation);

      completer.complete(orientation);
    });
  } catch (e) {
    completer.complete(Orientation.portrait);
  }

  return completer.future;
}