Flutter桌面版屏幕适配
小于 1 分钟
Flutter桌面版屏幕适配
class SizeChangesListener with WidgetsBindingObserver {
@override
void didChangeMetrics() {
super.didChangeMetrics();
ScreenUtil.init(
BoxConstraints(
maxWidth: width,//new width
maxHeight: height//new height
),
designSize:Size(411.42857142857144, 683.4285714285714),
orientation: Orientation.portrait,
);
print('changed size');
}
}
void main() async {
runApp(MyApp());
if (Platform.isWindows || Platform.isLinux||Platform.isMacOS) {
WidgetsBinding.instance!.addObserver(SizeChangesListener());
}
}