You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

pubspec.yaml无flutter_native_splash配置区块 该如何解决?

解决 Your pubspec.yaml file does not contain a flutter_native_splash section 报错的方案

该报错是由于flutter_native_splash插件无法在pubspec.yaml中读取到对应配置段导致,按以下步骤操作即可解决:

  • 确认依赖已正确引入
    首先检查pubspec.yaml的dependencies或dev_dependencies下,已经正确添加flutter_native_splash依赖,依赖行缩进为2个空格,YAML格式无错误。
  • 添加正确的配置段
    在pubspec.yaml的最外层(与flutter、dependencies配置项平级的位置,不能嵌套在其他配置段内部),添加flutter_native_splash配置,示例如下:
    flutter_native_splash:
      # 启动页背景色,填写十六进制色值
      color: "#ffffff"
      # 启动页居中展示的图片路径,可选
      image: assets/images/splash_logo.png
      # 对应平台是否生成启动页
      android: true
      ios: true
      web: false
    
    注意:flutter_native_splash必须顶格书写,子配置项每一级缩进2个空格,禁止使用Tab缩进,否则YAML解析会出错。
  • 执行命令生成启动页
    配置修改保存后,先在终端执行flutter pub get刷新依赖,再执行dart run flutter_native_splash:create命令,插件就能正常读取配置生成启动页资源。

常见踩坑说明:多数用户报错是因为误将flutter_native_splash配置段写在了flutter配置的内部,插件无法识别到外层配置,调整到平级位置即可解决。

内容的提问来源于stack exchange,提问作者Khaoula MEHAR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 03:15:01