Created
March 20, 2020 10:30
-
-
Save jaripekkala/ce3de2dd5f64fcac3ac70d9ef4573d59 to your computer and use it in GitHub Desktop.
FakeDevicePixelRatio
This file contains hidden or 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/material.dart'; | |
void main() { | |
runApp( | |
FakeDevicePixelRatio( | |
fakeDevicePixelRatio: 1.5, | |
child: MyApp(), | |
), | |
); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar(title: Text('foo')), | |
body: Center( | |
child: Text('foo'), | |
), | |
), | |
); | |
} | |
} | |
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