Flutter桌面版屏幕适配

东方盛慧科技小于 1 分钟flutterflutter桌面版

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());
  }
}

上次编辑于:
贡献者: 雷勋