我在构造函数中初始化,但我不确定这是正确的方式?
class PlaceDialogWidget extends StatelessWidget {
final NearbyPlace currentPlace;
final SizeHelper sizeHelper;
PlaceDialogWidget(
{Key? key, required this.currentPlace, required this.sizeHelper})
: dialogWidth = sizeHelper.width! * 0.7,
dialogHeight = sizeHelper.height! * 0.5,
super(key: key);
late final double dialogWidth;
late final double dialogHeight;
}
1条答案
按热度按时间2guxujil1#
是的,这是在Dart中初始化变量的一种方法。
作为一种语言,Dart在构造函数方面有很多有趣的特性。请参阅使用构造函数了解更多信息
flutter
是使用dart
构建的框架,因此dart
的构造函数规则也适用于flutter
,因此StatelessWidget
类与任何其他dart
类类似。