Closed HidenoriMatsubayashi closed 1 year ago
We can send multiple display information, but it looks like only first entry is being used.
https://github.com/flutter/engine/blob/main/shell/common/display_manager.cc
We can get this information via FlutterView.Display.
import 'dart:ui';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
Display? _display;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_display = View.maybeOf(context)?.display;
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_display = null;
super.dispose();
}
@override
void didChangeMetrics() {
final Display? display = _display;
if (display == null) {
return;
}
print(display.id);
print(display.devicePixelRatio);
print(display.refreshRate);
print(display.size.width);
print(display.size.height);
}
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Placeholder(),
);
}
}
It looks like the embedder in flutter/engine added FlutterEngineNotifyDisplayUpdate API. I'm not sure how it works, but it looks like it's information for devtool.
https://github.com/flutter/engine/blob/main/shell/platform/embedder/embedder.h#L2777