我正在制作一个与另一个程序包交互的程序包。我正在使用具有默认值的flutter_colorpicker,但我提供的值可能等于或可能不等于null。这是我的一些代码:
content: ColorPicker(
onColorChanged: onChanged,
pickerColor: initialValue,
colorPickerWidth: colorPickerWidth, // could be null
displayThumbColor: displayThumbColor, // could be null
enableAlpha: enableAlpha, // could be null
enableLabel: enableLabel, // could be null
paletteType: paletteType, // could be null
pickerAreaHeightPercent: pickerAreaHeightPercent, // could be null
),
我是否必须提供自己的默认值才能与另一个软件包交互?我不必认为,因为程序包提供了自己的默认值,但它们似乎被忽略了。一些软件包的默认值是该类的私有值,我将无法提供它们。有什么我想念的吗?
这是另一个包的构造函数:
const ColorPicker({
@required this.pickerColor,
@required this.onColorChanged,
this.paletteType: PaletteType.hsv,
this.enableAlpha: true,
this.enableLabel: true,
this.displayThumbColor: false,
this.colorPickerWidth: 300.0,
this.pickerAreaHeightPercent: 1.0,
});
我收到此错误:
The method '*' was called on null.
Receiver: null
Tried calling: *(null)
引起错误的区域:
SizedBox(
width: widget.colorPickerWidth,
height: widget.colorPickerWidth * widget.pickerAreaHeightPercent, // this line
child: ColorPickerArea(currentHsvColor, (HSVColor color) {
setState(() => currentHsvColor = color);
widget.onColorChanged(currentHsvColor.toColor());
}, widget.paletteType),
),