【发布时间】:2018-11-13 21:38:57
【问题描述】:
我正在尝试使用以下代码
class NewItemCreate extends StatefulWidget{
@override
NewItemCreateState createState() => new NewItemCreateState();
}
class NewItemCreateState extends State<NewItemCreate>
{
File _image;
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_image = image;
});
print(_image.path);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.yellow,
appBar: new AppBar(
title: new Text("Report"),
elevation: 5.0,
),
body:
Center (
child: ListView(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
shrinkWrap: true,
children: <Widget>[
itemImage,
SizedBox(height: 18.0),
itemName,
SizedBox(height: 18.0),
itemLocation,
SizedBox(height: 18.0),
itemLocation,
SizedBox(height: 18.0),
itemTime,
SizedBox(height: 18.0),
Report,
SizedBox(height: 38.0),
],
)
)
);
}
final itemImage = Padding(
padding: EdgeInsets.symmetric(vertical: 25.0),
child: Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.lightBlueAccent.shade100,
elevation: 5.0,
child: MaterialButton(
minWidth: 200.0,
height: 300.0,
onPressed: (){
getImage();
},
color: Colors.lightGreenAccent,
child:
new Icon(Icons.add_a_photo, size: 150.0,color: Colors.blue,),
),
),
);
这里已经有一个问题了, Error: Only static members can be accessed in initializers what does this mean? 关于这个问题,但是,我真的应该为此使用“SingleTickerProviderStateMixin”吗?另外,这与单身人士有关吗? (我还在学习编程)
【问题讨论】:
-
上面哪一行代码导致了错误?
-
getImage() in the final itemImage
-
为了准确查看这个答案:stackoverflow.com/a/63165959/10563627