flutter_device_preview icon indicating copy to clipboard operation
flutter_device_preview copied to clipboard

Custom WidgetsBinding

Open aloisdeniel opened this issue 4 years ago • 1 comments

Ideally, a custom WidgetsBinding should be provided to emulate the host.

This would allow to emulate more things :

  • Application lifecycle events
  • Memory pressure event
  • Platform channels
  • A mouse pointer

The DevicePreview.appBuilder (injects a custom MediaQuery) and DevicePreview.of(context).locale parameters wouldn't be needed anymore too since they would be managed by the binding itself.

The issue is that the WidgetBindings.instance is unique and static, so it is not possible to override it only from the encapsulated user app.

aloisdeniel avatar Oct 20 '19 08:10 aloisdeniel

I need to provide different aspectRatio on iOS and Android devices.

  double _calculateAspectRatio(Orientation orientation) {
    final Size screenSize = MediaQuery.of(context).size;

    if (Platform.isIOS && orientation == Orientation.portrait) {
      return (screenSize.height / screenSize.width) / 0.85;
    } else if (orientation == Orientation.portrait) {
      return (screenSize.height / screenSize.width);
    } else {
      return (screenSize.width / screenSize.height);
    }
  }

Simulate the platform channel could be a very good improvement!

enricobenedos avatar Apr 10 '20 14:04 enricobenedos