如果你项目需要调整自定义字体,字体大小适配、便捷的样式设置,那你可以尝试用一下这个方案。
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),
);
}
}