'Flutter app orientation changes from portrait to landscape

When I load my flutter app which uses " scan: ^1.6.0 " package once the scanner gets mounted my app shifts orientation from portrait to landscape this only happens in tablet mode where the orientation is fixed to landscape mode ,On the mobile app I do not face this issue, I have also set the screenOrientation to landscape in the AndroidManifest.xml file.

AndroidManifest.xml

main.dart



Solution 1:[1]

The creator forced the orientation on native platforms, to change this on Android, you need change on native, I tried, but will need change the design, because is not reponsive and dont work on landscape.

The code that force the orientation. You can see the complete code in android/src/main/java/com/chavesgu/scan/ScanViewNew.java

public ScanViewNew(
  Context context, 
  Activity activity, 
  @NonNull ActivityPluginBinding activityPluginBinding,
  @Nullable Map<String, Object> args,
) {
  super(context, null);

  this.context = context;
  this.activity = activity;
  
  // This line force the orientation
  activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  
  this.activityPluginBinding = activityPluginBinding;
  activityPluginBinding.addRequestPermissionsResultListener(this);
  this.scale = (double) args.get("scale");

  checkPermission();
}

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Daniel Fernandes