首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何设置颤振背景图像

如何设置颤振背景图像
EN

Stack Overflow用户
提问于 2022-11-22 15:47:06
回答 2查看 35关注 0票数 0

这是我的pubspec.yaml

代码语言:javascript
运行
复制
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:
      - images/img_rectangle1.jpg

我已经建立了一个资产文件夹,并将其包含在my.png图片中;但是,我在使用这些小部件时遇到了困难。

代码语言:javascript
运行
复制
@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: const Text("Korean vocabulary related to traits"),
      centerTitle: false,
      backgroundColor:  const Color(0xFFEC74C8),
    ),
    body: Row(
      children: [
        Expanded(
            child: ListView.builder(
              itemCount: koreanNameList.length,
              itemBuilder: (context, index) {
                KoreanItem item = koreanNameList[index];
                return Draggable<KoreanItem>(
                    data: item,
                    dragAnchorStrategy: pointerDragAnchorStrategy,
                    feedback: KoreanNameCard(item: item),
                    child: KoreanNameCard(item: item));
              },
            )),
        Expanded(
            child: ListView.builder(
              itemCount: englishanswers.length,
              itemBuilder: (context, index) {
                return buildEnglishanswerColumn(englishanswers[index]);
              },
            )),
      ],
    ),
  );
}

那么,放背景图片的容器到底应该放在哪里呢?

我试过用

代码语言:javascript
运行
复制
AssetImage

但它并没有显示在我的应用程序上。

EN

Stack Overflow用户

回答已采纳

发布于 2022-11-22 16:35:47

您需要在pubspec.yaml上指定 assets

Flutter使用位于项目根目录的pubspec.yaml文件来标识应用程序所需的资产。

下面是一个示例:

颤振:资产:-资产/图像/背景。

若要包含目录下的所有资产,请指定目录名,其末尾为/字符:

颤振:资产:-资产/-资产/图像/

使用图像资产的样本

代码语言:javascript
运行
复制
Container(
  height: double.infinity,
  width: double.infinity,
  decoration: const BoxDecoration(
    image: DecorationImage(
      image: AssetImage("assets/splash/background.png"),
      fit: BoxFit.cover,
    ),
  ),
  child: const Center(
    child: Text(
      'Hello World!',
      style: TextStyle(color: Colors.white),
    ),
  ),
);

参考添加资产和图像

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74535370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档