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

如何不使用flutter_launcher_icons修改应用默认启动页/闪屏?含自定义动画或禁用需求

手动修改Flutter应用启动页/闪屏(无需flutter_launcher_icons)

一、修改默认静态启动页

Android端

  • 定位到android/app/src/main/res/drawable/launch_background.xml,这是默认启动页的布局文件
  • 替换背景:把文件里的android:drawable="@drawable/launch_background"改成你的自定义图片资源,比如@drawable/your_splash_image,记得将图片放到对应分辨率的drawable文件夹(drawable-mdpi、hdpi等)
  • 不需要文字的话,直接删掉文件里的TextView节点即可

iOS端

  • 打开ios/Runner/Assets.xcassets,找到LaunchImage分组
  • 替换分组里的1x、2x、3x图片为你的自定义启动图(对应尺寸参考:320x480、640x960、960x1440,或按苹果官方适配规范调整)
  • 若要实现全屏无黑边,在ios/Runner/Info.plist中添加或确认以下配置:
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    
    然后打开LaunchScreen.storyboard,调整ImageView的约束让图片铺满屏幕

二、实现自定义动画启动页

核心思路

Flutter的默认闪屏是原生层加载时显示的,动画启动页需要先通过原生静态闪屏过渡,进入Flutter页面后播放动画,最后跳转至主页面(避免直接去掉原生闪屏导致的短暂空白)

具体步骤

  1. 先按上面的方法设置一个简洁的原生静态闪屏(比如仅放置logo)
  2. 创建Flutter动画页面:
    import 'package:flutter/material.dart';
    import 'package:flutter/scheduler.dart';
    
    class SplashAnimationPage extends StatefulWidget {
      const SplashAnimationPage({super.key});
    
      @override
      State<SplashAnimationPage> createState() => _SplashAnimationPageState();
    }
    
    class _SplashAnimationPageState extends State<SplashAnimationPage> with SingleTickerProviderStateMixin {
      late AnimationController _controller;
      late Animation<double> _animation;
    
      @override
      void initState() {
        super.initState();
        _controller = AnimationController(
          duration: const Duration(seconds: 2),
          vsync: this,
        );
        _animation = CurvedAnimation(parent: _controller, curve: Curves.easeInOut);
    
        // 等待页面渲染后启动动画,完成后跳转主页面
        SchedulerBinding.instance.addPostFrameCallback((_) {
          _controller.forward();
          Future.delayed(const Duration(seconds: 2), () {
            Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const YourMainPage()));
          });
        });
      }
    
      @override
      void dispose() {
        _controller.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.white,
          body: Center(
            child: FadeTransition(
              opacity: _animation,
              child: ScaleTransition(
                scale: _animation,
                child: Image.asset('assets/images/your_logo.png'),
              ),
            ),
          ),
        );
      }
    }
    
  3. 在main.dart中将动画页设为初始路由:
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          home: const SplashAnimationPage(),
        );
      }
    }
    

三、禁用默认闪屏

Android端

  • 打开android/app/src/main/res/values/styles.xml,找到LaunchTheme,修改为:
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
      <item name="android:windowBackground">@android:color/transparent</item>
      <item name="android:windowContentOverlay">@null</item>
    </style>
    
  • 确认android/app/src/main/AndroidManifest.xml中,activity的theme属性已设置为@style/LaunchTheme
  • 注意:禁用后启动时可能出现短暂白屏/黑屏,建议配合Flutter端的启动页逻辑处理

iOS端

  • 打开ios/Runner/Info.plist,删除或注释掉以下配置:
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    
    同时删除LaunchScreen.storyboard文件
  • 或直接将LaunchImage替换为透明图片,同样需注意启动时的短暂空白问题

内容的提问来源于stack exchange,提问作者mohammad-fawaz-cp

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 15:25:06