[英]How to write a function (in flutter-dart) so that it accepts certain parameters when we call that function?
This is my code:这是我的代码:
Text ButtonText = Text(
_buttonText, style: TextStyle(
color: Colors.white,
fontFamily: 'San francisco',
//fontSize: 21.0.ssp,
letterSpacing: 2.0,
wordSpacing: 2.0
),
);
when I use this Text in my button widget, I want to set font size explicitly.当我在按钮小部件中使用此文本时,我想明确设置字体大小。 How can I do that?
我怎样才能做到这一点?
you can create a class for your situation we can call it customtext here is an example code:你可以为你的情况创建一个 class 我们可以称之为 customtext 这里是一个示例代码:
import 'package:flutter/material.dart';
class CustomText extends StatelessWidget {
final String text;
final double size;
final Color color;
final FontWeight weight;
// name constructor that has a positional parameters with the text required
// and the other parameters optional
CustomText({@required this.text, this.size,this.color,this.weight});
@override
Widget build(BuildContext context) {
return Text(
text,style: TextStyle(fontSize: size ?? 16, color: color ?? Colors.black, fontWeight: weight ?? FontWeight.normal),
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.