【发布时间】:2020-10-08 15:59:04
【问题描述】:
我有照片的 ListView,我试图从图库中获取照片并将它们显示在屏幕上,但问题是当我按下添加新照片时,整张照片都会更改为新照片。
我想单独更改每张照片而不更改其他照片。
File _image;
final picker = ImagePicker();
Future getImage() async {
final image = await picker.getImage(source: ImageSource.gallery);
setState(() {
_image = File(image.path);
print((image.path));
});
}
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 1,
itemBuilder: (BuildContext context, int index){
return Row(
children: <Widget>[
GestureDetector(
onTap: (){
getImage();
},
child: Padding(
padding: EdgeInsets.only(left:5.0, right:5,top: 10),
child: Container(
height: 100.0,
width: 100.0,
decoration: BoxDecoration(
border: Border.all(),
image: DecorationImage(
image: _image == null ? AssetImage(
'assets/images/add_pic.jpg') : FileImage(_image),
fit: BoxFit.fill,
),
shape: BoxShape.rectangle,
),
),
),
),
【问题讨论】:
标签: image listview flutter dart