flutter - 如何在对话框中添加图像?
问题描述
但是,我似乎无法解决如何做到这一点。当我尝试添加图像时出现如下错误...
Exception has occurred.
FlutterError (Unable to load asset: assets/images/icons8-easy.png)
到目前为止,以下是我的代码:
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: null,
content: Container(
height: 100.h,
child: Column(
children: [
Container(
width: 100.w,
child: Image(image: AssetImage("assets/images/icons8-easy.png"),)
),
Container(
width: size.width * 0.8,
child: Text(
"Success",
style: TextStyle(
fontFamily: 'HelveticaNueue',
fontWeight: FontWeight.bold,
fontSize: 16.sp,
height: 1.5.h),
textAlign: TextAlign.center,
)),
],
),
)
));
这是我的 pubspec 文件
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
- assets/icons/
- assets/fonts/
- assets/Dialogflowservice/
解决方案
它与任何其他小部件相同。您只需在对话框中添加一列并在图像的小部件中添加。
还要确保你已经在你的 pubspec 中添加了你的资产。
推荐阅读
- html - 如何从输入字段搜索文本到文本区域,以及如何使用 Jquery 标记匹配结果?
- c++ - C++20 std::move 中的自赋值
- python - 如何将数字转换为熊猫列中的类别
- ios - UIScrollView 缩放到图像的特定区域
- python - pandas dataframe-如何查找在每一行中重复的单词
- android - MediaStore 在查询 DISPLAY_NAME 时返回 null
- postgresql - CodeBuild 到 RDS 的连接问题
- html - 视口元设置为设备宽度和初始比例的奇怪行为
- firebase - Flutter & Stream:getter 'name' 被调用为 null
- python - 处理函数时检测到错误
70_SetVals:, E121: Undefined variable: g:pydiction_location -- 按下选项卡按钮时发生错误