我想用一些构造函数创建自定义 TextStyle,例如 Color 和 fontWeight,因此稍后在屏幕 View 中字体和大小的样式是固定的,但只能自定义颜色和字体粗细,
class TextStyles {
final Color fontColor;
const TextStyles({
this.fontColor = Colors.black;
});
static const TextStyle buttonText = const TextStyle(
fontFamily: 'Montserrat',
color: fontColor,
fontWeight: FontWeight.w700,
fontSize: 14.0
);
}
class CustomButton extends StatelessWidget {
....
final Function onPressed;
const CustomButton({
Key key,
...
@required this.onPressed,
this.textSize = 14.0,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final CreateBlueButton = FlatButton(
color: background,
child: Text(
text,
style: TextStyleCustom,
)
);
return Container(
constraints: BoxConstraints.expand(height: 53),
...
最佳答案
这里是你需要的:
import 'package:flutter/material.dart';
class MyTextStyle extends TextStyle {
final Color color;
final FontWeight fontWeight;
final double size;
final String fontFamily;
const MyTextStyle({
@required this.color,
@required this.fontWeight,
this.size = 14,
this.fontFamily = 'Montserrat',
}) : assert(color != null && fontWeight != null),
super(
color: color,
fontWeight: fontWeight,
fontSize: size,
fontFamily: fontFamily,
);
}
关于Flutter - 如何管理一个文件中的 TextStyle 'text_style.dart' 函数以在另一个 View 中调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56898118/