我想从网络图窗口内调用提供商类的函数
我想在网络窗口小部件中显示从我要求的端点返回的图像。每个要返回的图像都有一个单独的ID。在提出端点请求时,我需要更新此ID。我该怎么做?我使用提供商类。
//provider
class InfoDetailsProvider with ChangeNotifier {
HttpService _httpService = HttpService();
Future<StorageItem> getImage(String imageId ) async {
StorageItem storageItem;
_httpService.initWithToken(authToken);
final urlImage= "http://example../$imageId";
try {
final result = await _httpService.request(url: urlImage, method: Method.GET);
if (result != null) {
if (result is d.Response) {
var responseData = result.data;
storageItem=responseData.forEach((key,value){ });
notifyListeners();
return storageItem;
}
}
} on d.DioError catch (error) {
throw error;
}
return storageItem;
}
}
我想在信息详细信息屏幕中调用getImage函数以显示图像。是否可以在NetworkImage Widget中调用函数?
//Screen
class InfoDetailsState extends State<InfoDetailsScreen> {
var _isInit = true;
var _isLoading = false;
@override
void initState() {
super.initState();
}
@override
void didChangeDependencies() {
if (_isInit) {
setState(() {
_isLoading = true;
});
Provider.of<InfoDetailsProvider>(context).getImage(imageId);
}
_isInit = false;
super.didChangeDependencies();
}
...
return Scaffold(
appBar: AppBar(),
body: RefreshIndicator(
....
child: SlidingUpPanel(
...
body: SafeArea(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
** //Should I call function here?**
),
fit: BoxFit.fill,
),
));
I want to show the image returned from the endpoint that I requested, in the NetworkImage widget. Each image to return has a separate id. I need to update this id when making request to endpoint. How can I do that? I use provider class.
//provider
class InfoDetailsProvider with ChangeNotifier {
HttpService _httpService = HttpService();
Future<StorageItem> getImage(String imageId ) async {
StorageItem storageItem;
_httpService.initWithToken(authToken);
final urlImage= "http://example../$imageId";
try {
final result = await _httpService.request(url: urlImage, method: Method.GET);
if (result != null) {
if (result is d.Response) {
var responseData = result.data;
storageItem=responseData.forEach((key,value){ });
notifyListeners();
return storageItem;
}
}
} on d.DioError catch (error) {
throw error;
}
return storageItem;
}
}
I want to call getImage function in Info Details Screen to display image. Is it possible to call function with in NetworkImage widget?
//Screen
class InfoDetailsState extends State<InfoDetailsScreen> {
var _isInit = true;
var _isLoading = false;
@override
void initState() {
super.initState();
}
@override
void didChangeDependencies() {
if (_isInit) {
setState(() {
_isLoading = true;
});
Provider.of<InfoDetailsProvider>(context).getImage(imageId);
}
_isInit = false;
super.didChangeDependencies();
}
...
return Scaffold(
appBar: AppBar(),
body: RefreshIndicator(
....
child: SlidingUpPanel(
...
body: SafeArea(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
** //Should I call function here?**
),
fit: BoxFit.fill,
),
));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解您的问题,解决方案是
,您可以定义您的函数,该功能将在
build> build
方法中调用提供商的函数,例如如果您还有更多问题,请在评论中询问。 :)
As far as I understand your question, the solution is
and you can define your function that will call provider's function inside the
build
method likeif you have further more question, ask in comment. :)