作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
padding
需要是可选的,所以如果我不传递任何填充参数,则需要为 0,但它不会接受构造函数中的任何值,这与 bool bold
不同。争论。
class QText extends StatelessWidget {
QText(this.text, this.size,
{this.align, this.bold = false, this.colour, this.font, this.padding});
final String text;
final double size;
final bool bold;
final Color colour;
final String font;
final TextAlign align;
final List<double> padding;
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(padding[0], padding[1],
padding[2], padding[3]),
child: Text(
text,
textAlign: align,
style: TextStyle(
fontSize: size,
fontWeight: (bold) ? FontWeight.bold : FontWeight.normal,
fontFamily: (font != '') ? font : '',
color: colour,
),
),
);
}
}
我似乎无法设置 QText(this.text, this.size,
或任何类似的东西,因为它会抛出错误
{this.align, this.bold = false, this.colour, this.font, this.padding = [0.0,0.0,0.0,0.0]]});Default values of an optional parameter must be constant.
而且我也无法设置 final List<double> padding ?? [0.0,0.0,0.0,0.0];
如果我不为它传递参数,我怎么能给它一个默认值呢?因为它毕竟应该是可选的,但 Padding
小部件也不接受无填充。
最佳答案
你试过吗:
QText(this.text, this.size, {this.align, this.bold = false, this.colour, this.font, this.padding = const <double>[0, 0, 0, 0]});
关于class - Dart 确保类中的可选列表参数不为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57201716/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!