这款开源的库,能够实现不一样屏幕尺寸的适配.responsive_builderweb
pubspec.yaml
引入库 responsive_builder: ^0.3.0
import 'package:responsive_builder/responsive_builder.dart';
ResponsiveBuilder( builder: (context, sizingInformation) { if (sizingInformation.deviceScreenType == DeviceScreenType.desktop) { return Container( color: Colors.blue, child: Text("desktop"), ); } if (sizingInformation.deviceScreenType == DeviceScreenType.tablet) { return Container( color: Colors.red, child: Text("tablet"), ); } if (sizingInformation.deviceScreenType == DeviceScreenType.watch) { return Container( color: Colors.yellow, child: Text("watch"), ); } return Container( color: Colors.green, child: Text("mobile"), ); }, ),
以上代码,能够在不一样尺寸的状况下,返回不一样的Container.
其余参考文章ui