gpt4 book ai didi

dart - Flutter-如何打开手机图库?

转载 作者:IT王子 更新时间:2023-10-29 07:00:35 27 4
gpt4 key购买 nike

我想在这里打开画廊目录,我正在使用这段代码但是显示了所有选项我想打开唯一的画廊。

List images;
int maxImageNo = 10;
bool selectSingleImage = false;
File _imageFile;
_pickImageFromGallery() async {
File file;
String result;
try {
result = await FlutterImagePickCrop.pickAndCropImage(_gallery);
} on PlatformException catch (e) {
result = e.message;
print(e.message);
}
if (!mounted) return;

setState(() {
imageFile = new File(result);
_platformMessage = result;
});}

enter image description here

最佳答案

如果您只想从图库中选择,那么您可以使用 image_picker插入。如果裁剪对您很重要,那么我会重新考虑我的答案,因为 image_picker 没有提供。

import 'package:image_picker/image_picker.dart';

class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
File _image;

Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);

setState(() {
_image = image;
});
}

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Image Picker Example'),
),
body: new Center(
child: _image == null
? new Text('No image selected.')
: new Image.file(_image),
),
floatingActionButton: new FloatingActionButton(
onPressed: getImage,
tooltip: 'Pick Image',
child: new Icon(Icons.add_a_photo),
),
);
}
}

关于dart - Flutter-如何打开手机图库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51554755/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com