从库中选择图像时,提供程序出现问题,它没有出现在 UI 中。
我尝试改用 Text ,它确实工作得很好。我认为问题出在futureBuilder之类的
class ImageController extends ChangeNotifier {
Future<File> _image;
pickImageFromGallery(ImageSource source) {
_image = ImagePicker.pickImage(source: source);
NotificationListener();
}
Widget imageFromGallery() {
return FutureBuilder<File>(
future: _image,
builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
null != snapshot.data) {
Utility.saveImageToPreferences(
Utility.base64String(snapshot.data.readAsBytesSync()));
return
Image.file(
snapshot.data,
);
} else if (null != snapshot.error) {
return const Text(
'Error Picking Image',
textAlign: TextAlign.center,
);
} else {
return const Text(
'No Image Selected',
textAlign: TextAlign.center,
);
}
},
);
}
}
这就是我从另一个widgit显示它的方式
Consumer<ImageController>(
builder: (context, image,child){
return Provider.of<ImageController>(context).imageFromGallery();
},
),