使用 Getx Flutter 使用相机后如何显示图像?它显示 AssetImage('assets/images/kad.jpg') 但拍照后它不显示来自相机的图片..请帮帮我
imageController.dart
class ImageController extends GetxController {
static ImageController get to => Get.find<ImageController>();
File image;
String imagePath;
final _picker = ImagePicker();
Future<void> getImage() async {
final pickedFile = await _picker.getImage(source: ImageSource.camera);
if (pickedFile != null) {
image = File(pickedFile.path);
File imagePath = File(pickedFile.path);
print(imagePath);
} else {
print('No image selected.');
}
}
}
在 UI.dart 上
class UploadPicture extends StatelessWidget {
final imageController = ImageController.to;
..........
image: DecorationImage(
image: imageController.image == null
? AssetImage('assets/images/kad.jpg')
: Image.file(File(imageController.image.path))),```
it show AssetImage('assets/images/kad.jpg') but after take picture it not show the picture from camera.. please help me