【问题标题】:how to add an full screen image as splash screen on flutter如何在颤动中添加全屏图像作为启动画面
【发布时间】:2021-11-19 23:58:39
【问题描述】:

**大家好,我是 Flutter 的新手,已经使用了 1 或 2 个月,我的问题是,有什么方法可以将全屏图像添加为我的应用程序的启动画面?我被困在这里我尝试了很多方法,它们都没有按照我想要的方式工作**

【问题讨论】:

  • 使用这个包flutter_native_splash
  • 是的,兄弟我试过了,但我不允许我使用全屏
  • 看看这个solution可能会帮助你
  • 我找到了一种使用 flutter_splash_native 包的方法,我们可以将图像作为背景图像作为初始屏幕图像放置

标签: flutter dart user-interface splash-screen


【解决方案1】:
    import 'package:flutter/material.dart';

class Splash extends StatefulWidget {
  @override
  _SplashState createState() => _SplashState();
}

class _SplashState extends State<Splash> {
  @override
  void initState() {
    Future.delayed(Duration(seconds: 3), () {
      Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => CalendarWidget(title: 'Calendar')));
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        child: Image.network(
          'https://images.pexels.com/photos/1987301/pexels-photo-1987301.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500',
          fit: BoxFit.cover,
        ),
      ),
    );
  }
}

【讨论】:

  • 自己使用图片资源,就像你想使用 url 或资源图片一样。并将导航器下一个屏幕替换为您所需的类。
  • 这真的是一个闪屏,因为我猜它不会在应用程序初始化时加载
  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
  • 用这个屏幕从'main.dart'开始你的应用程序,它会在开始时加载。在此屏幕之后,您可以等待将用户带到您想要的任何屏幕。
  • 如果您提供解释为什么这是首选解决方案并解释它是如何工作的,它会更有帮助。我们想要教育,而不仅仅是提供代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-01
  • 2021-07-09
  • 1970-01-01
  • 2021-10-28
  • 1970-01-01
  • 2021-12-15
  • 1970-01-01
相关资源
最近更新 更多