如何在弹奏中使用堆栈小部件中的图像?
在堆栈小部件中使用image时,我遇到了一个错误:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
...
这是我的代码:
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child: Flexible(
child: Image.asset(itemData["image"])
),
),
const Positioned(
...
),
],
),
],
),
);
}
当然,我在pubspec.yaml
中定义了我的图像资产,然后尝试删除flexible
widget也在其上方添加行
层,但是它仍然无法正常工作...
是我删除fixible
widget的错误
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/image2.jpg
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:675:14)
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "assets/images/image2.jpg")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#898db(), name:
"assets/images/image2.jpg", scale: 1.0)
这 堆栈小部件,我的代码怎么了? 谢谢您的到来,希望您能有解决方案。干杯
I got an error when using Image inside Stack widget :
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
...
this is my code :
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child: Flexible(
child: Image.asset(itemData["image"])
),
),
const Positioned(
...
),
],
),
],
),
);
}
of course, I defined my image assets in pubspec.yaml
and I try to remove flexible
widget also add Row
layer above it, but it's still not working either...
this is my error when I remove flexible
widget :
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/image2.jpg
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:675:14)
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "assets/images/image2.jpg")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#898db(), name:
"assets/images/image2.jpg", scale: 1.0)
So, How I can use (multiple) Images inside Stack Widget, and what's wrong with my code?
thank you for coming and I hope you have the solution. cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用扩展的小部件包裹堆栈。我尝试了下面的示例,对我有用
Wrap the Stack with expanded widget. I tried with the example below and it worked for me
因此,RenderObject无法在UI中绘制您在UI中构建的内容,因为您在图像上缠绕着灵活的
图像渲染问题:请参阅 https://docs.flutter.dev/development/platform-integration/web-images
so renderobject not able to paint what you construct in UI because of you wraped flexible over Image
for image rendering issue : refer https://docs.flutter.dev/development/platform-integration/web-images