gpt4 book ai didi

从图库中选择后 flutter 设置图像

转载 作者:IT王子 更新时间:2023-10-29 06:43:21 24 4
gpt4 key购买 nike

       File profileImg;

Widget profilePic() {
return Stack(
children: <Widget>[
new Image.file(profileImg),
Positioned(
left: 50.0,
right: 50.0,
bottom: 40.0,
height: 64.0,

child: RaisedGradientButton(
onPressed: () async {
File image= await ImagePicker.pickImage(source:ImageSource.gallery);
image=profileImg;
print(image.path);
},
child: new Text(
"Upload",
style: TextStyle(fontSize: 20.0, color: Colors.white),
),
gradient: LinearGradient(
colors: <Color>[
const Color(0xFF000000),
const Color(0xFF000000),
const Color(0xFF40079B)
],
),
), // child widget
),
]);
}

我创建了一张图片,在图片底部我有一个按钮可以从图库中选择图片。在从图库中选择图片之前,我想在从图库中选择图片后设置图片的背景色在imageview中设置选中的图片

最佳答案

使用 Image_pickerFutureBuilder 显示所选图库图像的最小示例。

Future<File> profileImg;

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("Gallery Image Picker"),
),
body: profilePic());
}

Widget profilePic() {
return ListView(children: <Widget>[
FutureBuilder(
builder: (context, data) {
if (data.hasData) {
return Container(
height: 200.0,
child: Image.file(
data.data,
fit: BoxFit.contain,
height: 200.0,
),
color: Colors.blue,
);
}
return Container(
height: 200.0,
child: Image.network('https://via.placeholder.com/150'),
color: Colors.blue,
);
},
future: profileImg,
),
RaisedButton(
color: Colors.blue,
onPressed: () {
profileImg = ImagePicker.pickImage(source: ImageSource.gallery)
.whenComplete(() {
setState(() {});
});
},
child: new Text(
"Pick Gallery Image",
style: TextStyle(fontSize: 20.0, color: Colors.white),
),
),
]);
}

关于从图库中选择后 flutter 设置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54125675/

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