当我尝试向列表视图动态添加图像以显示来自相机选择器的多个图像时。 如何将图像列表添加到列表视图以显示图像。
点击图片的代码:
Future getImage() async {
File images;
File _images = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
images = _images;
image.add(images.path);
});
}
然后在futurebuilder中使用
: child: new ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index)
{
print(image[index].toString());
return new UserWidgets(imageURL:
image[index].toString());
},
itemCount: image.length,
),
),
),
然后我的视图代码如下:
class UserWidgets extends StatelessWidget
{
final String imageURL;
// final String imageType;
const UserWidgets ({Key key, this.imageURL}) : super(key: key);
@override
Widget build(BuildContext context) {
// print(this.imageType);
VideoPlayerController playerController;
VoidCallback listener;
Widget play=new Icon(Icons.play_arrow);
Widget pause=new Icon(Icons.pause);
new Container(
height: 200.0,
child: new Card(
child: new Column(
children: <Widget>[
new GestureDetector(
onTap: ()
{
},
child:
new Image.file( File(imageURL)
,fit: BoxFit.cover,
height: 200.0,
width: 150.0,
),
)
],
)
),
)
},
我该如何解决?
答案 0 :(得分:0)
使用
List<File> images = [];
代替
File images;
与
File _image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
images.add(_image);
});
}