這款開源的庫,能夠實現不一樣屏幕尺寸的適配.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