Created
November 8, 2019 00:48
-
-
Save ardera/25a8c81a54fb37b0dc750d383caac5d9 to your computer and use it in GitHub Desktop.
A simple flutter widget that can simulate/fake a different pixel ratio for all it's children. Can be the root widget, i.e. the widget given to runApp(). Useful for when your device/emulator doesn't properly calculate the devicePixelRatio.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/widgets.dart'; | |
class FakeDevicePixelRatio extends StatelessWidget { | |
final num fakeDevicePixelRatio; | |
final Widget child; | |
FakeDevicePixelRatio({this.fakeDevicePixelRatio, this.child}) : assert(fakeDevicePixelRatio != null); | |
@override | |
Widget build(BuildContext context) { | |
final ratio = fakeDevicePixelRatio / WidgetsBinding.instance.window.devicePixelRatio; | |
return FractionallySizedBox( | |
widthFactor: 1/ratio, | |
heightFactor: 1/ratio, | |
child: Transform.scale( | |
scale: ratio, | |
child: child | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing!
updated it to work with current version: