我想让TextStyle / fontSize简化我的应用程序。
要做到这一点,就必须做好准备。“
fontSize: Get.width * .030,
的附加代码,类似于颜色
{彩色= Colors.white}
这是我要定制的代码..。
TextStyle _textStyle({Color color = Colors.white}) {
return GoogleFonts.getFont(
'Unica One',
fontSize: Get.width * .030,
color: color,
letterSpacing: 0.5,
);
}它应该是这样的,但不幸的是,我不知道如何正确地把它组合起来
TextStyle _textStyle({Color color = Colors.white}{FontSize fontSize = Get.width * .030}) {
return GoogleFonts.getFont(
'Unica One',
fontSize: fontSize,
color: color,
letterSpacing: 0.5,
);
}发布于 2021-08-17 12:09:34
带有样式的文本类,
class StoryText extends Text {
StoryText(String title, {Color mColor, double mFontSize})
: super(title,
style: GoogleFonts.getFont(
'Unica One',
fontSize: mFontSize,
color: mColor,
letterSpacing: 0.5,
));
}
// Use of above class
StoryText('title', mColor: Colors.red, mFontSize: Get.width * .030,),发布于 2021-08-17 11:37:27
需要将FontSize类型更改为double。
TextStyle _textStyle({Color color = Colors.white ,double fontSize = Get.width * .030}) {
return GoogleFonts.getFont(
'Unica One',
fontSize: fontSize,
color: color,
letterSpacing: 0.5,
);
}```发布于 2021-08-18 00:53:00
您能告诉我如何在"hintText:“中使用"TextField (”)吗?
当我这样做的时候
hintStyle: StyledText (
color: Colors.black,
),那么我就得到了错误
“参数类型'StyledText‘不能分配给参数类型'TextStyle?’(文档)”
我已经修改了你的代码,使其工作到目前为止,再次感谢你的..只想与"hintStyle“一起使用
import 'package: flutter / cupertino.dart';
import 'package: flutter / material.dart';
import 'package: google_fonts / google_fonts.dart';
class StyledText extends Text {
StyledText (
String title,
{
double fontSize = 10.5,
color = Colors.white,
fontWeight = FontWeight.w100,
letterSpacing = 0.5,
textAlign: TextAlign.center,
})
: super (title,
style: GoogleFonts.getFont (
'Unica One',
fontSize: fontSize,
color: color,
fontWeight: fontWeight,
letterSpacing: 0.5,
),
textAlign: textAlign,
);
}https://stackoverflow.com/questions/68815981
复制相似问题