Commit 4d73cf5c authored by kgiesing's avatar kgiesing

Add device pixel ratio to MediaQuery

parent 72931955
......@@ -77,15 +77,11 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver {
GlobalObjectKey _navigator;
Size _size;
EdgeDims _padding;
LocaleQueryData _localeData;
void initState() {
super.initState();
_navigator = new GlobalObjectKey(this);
_size = ui.window.size;
_padding = _getPadding(ui.window);
didChangeLocale(ui.window.locale);
WidgetFlutterBinding.instance.addObserver(this);
}
......@@ -106,10 +102,10 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver {
return result;
}
void didChangeSize(Size size) {
void didChangeMetrics() {
setState(() {
_size = size;
_padding = _getPadding(ui.window);
// The properties of ui.window have changed. We use them in our build
// function, so we need setState(), but we don't cache anything locally.
});
}
......@@ -150,7 +146,11 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver {
ThemeData theme = config.theme ?? new ThemeData.fallback();
Widget result = new MediaQuery(
data: new MediaQueryData(size: _size, padding: _padding),
data: new MediaQueryData(
size: ui.window.size,
devicePixelRatio: ui.window.devicePixelRatio,
padding: _getPadding(ui.window)
),
child: new LocaleQuery(
data: _localeData,
child: new AnimatedTheme(
......
......@@ -14,7 +14,7 @@ import 'framework.dart';
class BindingObserver {
bool didPopRoute() => false;
void didChangeSize(Size size) { }
void didChangeMetrics() { }
void didChangeLocale(ui.Locale locale) { }
void didChangeAppLifecycleState(ui.AppLifecycleState state) { }
}
......@@ -62,7 +62,7 @@ class WidgetFlutterBinding extends BindingBase with Scheduler, Gesturer, Rendere
void handleMetricsChanged() {
super.handleMetricsChanged();
for (BindingObserver observer in _observers)
observer.didChangeSize(ui.window.size);
observer.didChangeMetrics(ui.window.size);
}
void handleLocaleChanged() {
......
......@@ -16,11 +16,16 @@ enum Orientation {
/// The result of a media query.
class MediaQueryData {
const MediaQueryData({ this.size, this.padding });
const MediaQueryData({ this.size, this.devicePixelRatio, this.padding });
/// The size of the media (e.g, the size of the screen).
final Size size;
/// The number of device pixels for each logical pixel. This number might not
/// be a power of two. Indeed, it might not even be an integer. For example,
/// the Nexus 6 has a device pixel ratio of 3.5.
final double devicePixelRatio;
/// The padding around the edges of the media (e.g., the screen).
final EdgeDims padding;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment