我在 flutter 中使用了颜色选择器插件,但对话框或颜色选择器本身遇到了错误。这是颜色选择器对话框的代码:
Color selectedColor;
double strokeWidth;
void initState(){
super.initState();
selectedColor = Colors.black;
strokeWidth = 2.0;
}
void selectColor(){
showDialog(
context: context,
builder: (_)=>
AlertDialog(
title: const Text('Pick a color!'),
content: SingleChildScrollView(
child: ColorPicker(
pickerColor: selectedColor,
showLabel: true,
onColorChanged: (color){
this.setState(() {
selectedColor = color;
});
},
),
),
actions: <Widget>[
TextButton(
onPressed: Navigator.of(context).pop,
child: Text("Close")
)
],
)
);
}
这是我遇到的错误:
The following NoSuchMethodError was thrown building RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#f296e](state: RawGestureDetectorState#9ea30(gestures: <none>, behavior: opaque)):
The getter 'red' was called on null.
Receiver: null
Tried calling: red
The relevant error-causing widget was:
SingleChildScrollView file:///E:/nush/painting_app/lib/main.dart
答案 0 :(得分:0)
使用调试器单步执行您的代码,看看“The getter 'red' was called on null”实际发生的时间。