flutter 开发踩坑集

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:15   2232   0

一、 TextField设置高度后,文字无法居中

解决方案:

TextField(
        style: TextStyle(
        ),
        decoration: InputDecoration(
          prefixIcon: ImageUtils.getImage("search")/*Icon(Icons.search)*/,
          hintText: widget.hint,
          fillColor: Color(0xfff1f1f2),
          contentPadding: EdgeInsets.all(0),//设置输入内容垂直居中
          border: OutlineInputBorder(
            borderSide: BorderSide.none,
//              borderRadius: BorderRadius.circular(20)
          ),
        ),
      )
  1. 设置decoration属性,在InputDecoration中设置contentPadding: EdgeInsets.all(0),
  2. 在InputDecoration中设置border属性,不能直接设置InputBorder.none,否则还是不能居中。

二、项目使用window.physicalSize和设定尺寸作比来做适配,奇怪的某些界面偶现的错乱问题

解决方案:(我的是由于项目中使用了隐藏导航栏await SystemChrome.setEnabledSystemUIOverlays([]);的原因,可能还有其他的因素会影响到window.physicalSize的获取计算问题),

void main() async {
  return SentryUtil.wrap(() async {
    WidgetsFlutterBinding.ensureInitialized();
    await SystemChrome.setPreferredOrientations(
        [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
    if (Platform.isIOS) {
      await ScreenRotationiOS.changeScreenOrientation(
          DeviceOrientationMask.Landscape);
    }
    Devices.init(width: 1080, height: 810);
    runApp(MyApp(
      appRoutes: routes,
      home: HomeScreen(),
    ));
    //这个需要放置在runApp后,不影响项目内部的window.physicalSize的获取
    await SystemChrome.setEnabledSystemUIOverlays([]);
  }, dsn: kDebugMode ? null : sentryDsn);
}

//这个需要放置在runApp后,不影响项目内部的window.physicalSize的获取
await SystemChrome.setEnabledSystemUIOverlays([]);

三、点击空白触发取消键盘

FocusScope.of(context).requestFocus(FocusNode());

四、软键盘把界面底部顶起,不让界面底部自动升起

Scaffold(
        resizeToAvoidBottomPadding: false,
        )

五、合并多个流做为一个stream

//yaml引入依赖 async 
//使用StreamGroup.merge()
StreamBuilder(
            stream: StreamGroup.merge(_streams),
            builder:....,)

六、

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP