【发布时间】:2021-12-30 10:58:25
【问题描述】:
我正在尝试打开一个对话框让用户添加两件事:
- 1- 视频缩略图(图片文件)
- 视频网址(字符串)
用户点击打开对话框的墨水瓶,然后用户单击对话框中的墨水瓶以选择视频缩略图,即图像文件。图像文件已设置,但它不会更新需要显示拾取文件的墨水池的状态。状态在热重载后更新。我正在使用提供程序来设置图像文件并使用它的实例来检查文件是否被选中。
更改通知器 ->
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class GetThumbnailImage extends ChangeNotifier {
PickedFile? image;
Future setImage(var file) async {
image = file;
notifyListeners();
}
}
使用更改通知器的小部件 ->
InkWell(
onTap: () {
getVideoImage().then((image) {
print(image);
if (image != null) {
_imageInstance.setImage(image);
}
});
},
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.25,
child: Center(
child: _imageInstance.image == null
? SizedBox(
width: 200,
height: 200,
child: FadeInImage(
image: NetworkImage(
apiBase + productId.toString() + apiLaterPart),
placeholder:
AssetImage("assets/images/Otherimages/addvideo.jpg"),
imageErrorBuilder: (context, error, stackTrace) {
return Image.asset(
'assets/images/Otherimages/addvideo.jpg',
fit: BoxFit.fitWidth);
},
fit: BoxFit.fitWidth,
),
)
: Image.file(
File(_imageInstance.image!.path),
),
),
))
【问题讨论】:
标签: flutter dialog provider state-management