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

咨询Flutter WebView项目中启动页(Splash Screen)的代码位置

找不到Flutter WebView应用启动页代码的原因及解决

你提供的main.dart和home_screen.dart里没有自定义启动页的代码,当前显示的启动页大概率来自以下两种情况:

1. Flutter默认的系统级启动页

这是Flutter框架在应用初始化阶段自动显示的启动界面,不属于Dart代码实现,而是由平台层面配置:

  • Android端:配置项在android/app/src/main/res/下的启动图资源,以及AndroidManifest.xml中对启动主题的定义
  • iOS端:配置项在ios/Runner/Assets.xcassets/LaunchImage.imageset里的启动图片,以及Info.plist中的相关设置
    这个启动页会在Flutter引擎加载完成后自动消失,跳转到你定义的HomeScreen。

2. 书籍示例的完整代码包含未引入的启动页文件

如果书籍里的示例明确有自定义启动页,可能是你缺失了相关代码文件:

  • 检查项目目录中是否存在SplashScreen.dart这类单独的启动页文件
  • 查看main.dart是否有被修改的版本,比如包含通过Future.delayed延迟跳转到首页的路由逻辑

自定义启动页的示例实现

如果需要手动添加自定义启动页,可以修改main.dart实现路由跳转:

import 'package:ch_08/screen/home_screen.dart';
import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      initialRoute: '/splash',
      routes: {
        '/splash': (context) => const SplashScreen(),
        '/home': (context) => HomeScreen(),
      },
    );
  }
}

class SplashScreen extends StatefulWidget {
  const SplashScreen({Key? key}) : super(key: key);

  @override
  State<SplashScreen> createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  @override
  void initState() {
    super.initState();
    // 延迟2秒后跳转到WebView首页
    Future.delayed(const Duration(seconds: 2), () {
      Navigator.pushReplacementNamed(context, '/home');
    });
  }

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      backgroundColor: Colors.white,
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(Icons.web, size: 80, color: Colors.blue),
            SizedBox(height: 20),
            Text('加载中...', style: TextStyle(fontSize: 18)),
          ],
        ),
      ),
    );
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 04:31:22