首页 > 解决方案 > 如何在对话框中添加图像?

问题描述

我正在尝试设计我的弹出警报对话框,如下图所示。 在此处输入图像描述

但是,我似乎无法解决如何做到这一点。当我尝试添加图像时出现如下错误...

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/

标签: flutterflutter-layout

解决方案


它与任何其他小部件相同。您只需在对话框中添加一列并在图像的小部件中添加。

还要确保你已经在你的 pubspec 中添加了你的资产。


推荐阅读