继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Flutter 适配移动端和web不同尺寸

全栈测试之路
关注TA
已关注
手记 19
粉丝 1
获赞 3

用到的库

这款开源的库,可以实现不同屏幕尺寸的适配.[responsive_builder]pub.dev/packages/responsive_builder

使用方法

1. pubspec.yaml引入库 responsive_builder: ^0.3.0

2. 代码引用 import 'package:responsive_builder/responsive_builder.dart';

3. 像使用普通控件一样,使用如下代码:

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.


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP