flutter 文本工具类

作者: 呆头呆脑雷 | 来源:发表于2023-05-05 10:53 被阅读0次

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

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),
    );
  }
}

相关文章

网友评论

    本文标题:flutter 文本工具类

    本文链接:https://www.haomeiwen.com/subject/glofsdtx.html