flutter_device_preview
flutter_device_preview copied to clipboard
Custom WidgetsBinding
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.
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!