flutter 文本工具类

如果你项目需要调整自定义字体,字体大小适配、便捷的样式设置,那你可以尝试用一下这个方案。

import 'package:flutter/material.dart';

const String segoeUI = "SegoeUI";
const String segoeUIBold = "SegoeUI-Bold";
const String segoeUISemibold = "SegoeUI-Semibold";
const String segoeUIBlack = "SegoeUI-BL";

class NFTtext extends StatelessWidget {
  final String? data;
  final double fontSize;
  final Color? color;
  final double? height;
  final int? maxlines;
  final TextOverflow? overflow;

  final String fontFamily;
  final FontWeight fontWeight;
  final TextStyle? style;

  const NFTtext(
    this.data, {
    Key? key,
    this.fontSize = 16,
    this.color,
    this.height,
    this.style,
    this.maxlines,
    this.overflow,
  })  : fontFamily = segoeUI,
        fontWeight = FontWeight.normal,
        super(key: key);

  const NFTtext.semiBold(
    this.data, {
    Key? key,
    this.fontSize = 16,
    this.color,
    this.height,
    this.style,
    this.maxlines,
    this.overflow,
  })  : fontFamily = segoeUISemibold,
        fontWeight = FontWeight.w600,
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Text(
      data ?? '',
      overflow: overflow,
      softWrap: true,
      // maxLines: maxlines,
      style: TextStyle(
        fontSize: fontSize,
        color: color,
        height: height,
        fontFamily: fontFamily,
        fontWeight: fontWeight,
      ).merge(style),
    );
  }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容