1

I am writing a platform view backed plugin for Flutter which uses OpenGL during rendering. When orientation changes I need to update EGL context to reference actual window-backed rendering context.

But how can I detect orientation change (e.g. in PlatformView subtype)?

Implemented Application.ActivityLifecycleCallbacks methods do not seem to get invoked at all on rotation after attaching then to the Application instance.

1 Answer 1

3

The reason that you are not getting a callback for the orientation change with the activity lifecycle callbacks is, in your manifest file, you can see

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

And this prevents your activity to be recreated on orientation changes with the native Android lifecycle. What you should be doing is, to use OrientationBuilder

e.g.

OrientationBuilder(
  builder: (context, orientation) {
    return GridView.count(
      // Create a grid with 2 columns in portrait mode,
      // or 3 columns in landscape mode.
      crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
    );
  },
);

For more information please check out https://flutter.dev/docs/cookbook/design/orientation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.