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 { ...@@ -77,15 +77,11 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver {
GlobalObjectKey _navigator; GlobalObjectKey _navigator;
Size _size;
EdgeDims _padding;
LocaleQueryData _localeData; LocaleQueryData _localeData;
void initState() { void initState() {
super.initState(); super.initState();
_navigator = new GlobalObjectKey(this); _navigator = new GlobalObjectKey(this);
_size = ui.window.size;
_padding = _getPadding(ui.window);
didChangeLocale(ui.window.locale); didChangeLocale(ui.window.locale);
WidgetFlutterBinding.instance.addObserver(this); WidgetFlutterBinding.instance.addObserver(this);
} }
...@@ -106,10 +102,10 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver { ...@@ -106,10 +102,10 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver {
return result; return result;
} }
void didChangeSize(Size size) { void didChangeMetrics() {
setState(() { setState(() {
_size = size; // The properties of ui.window have changed. We use them in our build
_padding = _getPadding(ui.window); // function, so we need setState(), but we don't cache anything locally.
}); });
} }
...@@ -150,7 +146,11 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver { ...@@ -150,7 +146,11 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver {
ThemeData theme = config.theme ?? new ThemeData.fallback(); ThemeData theme = config.theme ?? new ThemeData.fallback();
Widget result = new MediaQuery( 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( child: new LocaleQuery(
data: _localeData, data: _localeData,
child: new AnimatedTheme( child: new AnimatedTheme(
......
...@@ -14,7 +14,7 @@ import 'framework.dart'; ...@@ -14,7 +14,7 @@ import 'framework.dart';
class BindingObserver { class BindingObserver {
bool didPopRoute() => false; bool didPopRoute() => false;
void didChangeSize(Size size) { } void didChangeMetrics() { }
void didChangeLocale(ui.Locale locale) { } void didChangeLocale(ui.Locale locale) { }
void didChangeAppLifecycleState(ui.AppLifecycleState state) { } void didChangeAppLifecycleState(ui.AppLifecycleState state) { }
} }
...@@ -62,7 +62,7 @@ class WidgetFlutterBinding extends BindingBase with Scheduler, Gesturer, Rendere ...@@ -62,7 +62,7 @@ class WidgetFlutterBinding extends BindingBase with Scheduler, Gesturer, Rendere
void handleMetricsChanged() { void handleMetricsChanged() {
super.handleMetricsChanged(); super.handleMetricsChanged();
for (BindingObserver observer in _observers) for (BindingObserver observer in _observers)
observer.didChangeSize(ui.window.size); observer.didChangeMetrics(ui.window.size);
} }
void handleLocaleChanged() { void handleLocaleChanged() {
......
...@@ -16,11 +16,16 @@ enum Orientation { ...@@ -16,11 +16,16 @@ enum Orientation {
/// The result of a media query. /// The result of a media query.
class MediaQueryData { 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). /// The size of the media (e.g, the size of the screen).
final Size size; 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). /// The padding around the edges of the media (e.g., the screen).
final EdgeDims padding; 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