Flutter Text TextStyle 设置height: 1.5有透明边距,如何去除?

59 阅读1分钟

背景 :Text TextStyle 设置height: 1.5有透明边距

Container(
    alignment: Alignment.center,
    color: Colors.white,
    padding: EdgeInsets.only(
        left: 16.w, right: 16.w, top: 16.w, bottom: 32.w),
    child: Text(
        "Flutter  Text TextStyle 设置height: 1.5有透明边距",
      style: TextStyle(
        fontSize: 11.sp,
        color: DesignColors.color35,
        fontWeight: FontWeight.w400,
        height: 1.5,
      ),
     )),

需要去除透明边距

使用 StrutStyle
StrutStyle 可以更精确地控制文本的行高和基线对齐方式。你可以通过设置 StrutStyle 来避免不必要的边距。

Container(
    alignment: Alignment.center,
    color: Colors.white,
    padding: EdgeInsets.only(
        left: 16.w, right: 16.w, top: 16.w, bottom: 32.w),
    child: Text(
        "Durante el proceso de tu préstamo, te cobraremos intereses diarios y tarifas de servicio que van del 0.1% al 2%.",
      style: TextStyle(
        fontSize: 11.sp,
        color: DesignColors.color35,
        fontWeight: FontWeight.w400,
        height: 1.5,
      ),
      strutStyle: const StrutStyle(
        height: 1.5,
        forceStrutHeight: true,
      ),)),