ajinasokan / flutter_displaymode

A Flutter plugin to set display mode in Android
MIT License
184 stars 22 forks source link

[Detection] Detect current mode returned null on OnePlus 8 Pro #1

Closed AlexV525 closed 4 years ago

AlexV525 commented 4 years ago

Scenario

Check current display mode that the phone was activated, and set the flutter app to the current mode.

What exactly happened?

Try to find the selected display mode but returned null.

How I use this package

  @override
  void initState() {
    super.initState();
    checkSupportedDisplayMode();
  }

  Future<void> checkSupportedDisplayMode() async {
    try {
      final List<DisplayMode> modes = await FlutterDisplayMode.supported;
      modes.forEach(print);
      final DisplayMode m = modes.firstWhere((DisplayMode m) => m.selected, orElse: () => null);
      print(m);
    } on PlatformException catch (e) {
      print(e);
    }
  }

And the log goes like this:

Syncing files to device IN2020...
I/flutter (14847): #1 1080x2376 @ 60Hz
I/flutter (14847): #2 1440x3168 @ 120Hz
I/flutter (14847): #3 1440x3168 @ 60Hz
I/flutter (14847): #4 1080x2376 @ 120Hz
I/flutter (14847): null

Once I set the mode manually, it worked until the app was killed and restart.

AlexV525 commented 4 years ago

Or is this just designed for the app life cycle only?

ajinasokan commented 4 years ago

By default app is in an auto mode. Only when you select one, the selected flag is enabled.

Or is this just designed for the app life cycle only?

Yes you have to do this every time app starts. It is per session.

Edit: I have updated the read me with these info

AlexV525 commented 4 years ago

Okay that sounds reasonable, but I've checked the doc about Display.Mode doc, seems like it can be done on the Android that select the current mode according to platform's setting when the plugin is initializing.

AlexV525 commented 4 years ago

seems like it can be done on the Android that select the current mode according to platform's setting when the plugin is initializing.

If this can be added to the package, I'll try to create a PR for it.

ajinasokan commented 4 years ago

Yeah that will be great. But I think it should be another function. Something like "setPlatformDefault"

ajinasokan commented 4 years ago

Merged with #2