Flutter--Text封装


import 'package:flutter/material.dart';

class UIText extends StatelessWidget {

  final String text;

  final TextOverflow overflow;
  final TextAlign textAlign;
  final int maxLines;

  final double fontSize;
  final Color color;
  final FontWeight fontWeight;
  final List<Shadow> shadows;
  final TextDecoration decoration;
  final Color decorationColor;
  final TextDecorationStyle decorationStyle;
  final double decorationThickness;

  UIText(this.text, {
    this.overflow,
    this.textAlign,
    this.maxLines,
    this.fontSize,
    this.color,
    this.fontWeight,
    this.shadows,
    this.decoration,
    this.decorationColor,
    this.decorationStyle,
    this.decorationThickness
  });

  @override
  Widget build(BuildContext context) {
    return Text(
      text,
      maxLines: maxLines,
      overflow: overflow,
      textAlign: textAlign,
      style: TextStyle(
        color: color,
        fontSize: fontSize,
        fontWeight: fontWeight,  //文字宽度
        //letterSpacing: -5, //字母之间的间距,可以为负
        //wordSpacing: 10,  //单词之间的间距, 其实是增加文本中空格所占宽度
        //height: 10,  //Text高度为文本实际高度的几倍
        //leadingDistribution: TextLeadingDistribution.even, //针对高度属性的调整,文字在垂直方向的位置
        //textBaseline: TextBaseline.ideographic
        shadows: shadows,
        decoration: decoration,
        decorationColor: decorationColor,
        decorationStyle: decorationStyle,
        decorationThickness: decorationThickness
      ),
    );
  }

}

猜你喜欢

转载自blog.csdn.net/weixin_41735943/article/details/120668023