【问题标题】:remove default splash screen android & ios flutter删除默认启动屏幕 android & ios flutter
【发布时间】:2020-01-13 15:58:46
【问题描述】:

我更喜欢使用自定义启动画面,它允许我构建整个页面。所以,我正在尝试从 android 和 ios 中删除默认的启动画面

void main() async {
  flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

  runApp(MaterialApp(
    title: 'Navigation Basics',
    debugShowCheckedModeBanner: false,
    home: new SplashPage(),
    routes: {
      // When navigating to the "/" route, build the FirstScreen widget.
      '/home': (BuildContext context) => new FirstRoute(),
    },
  ));
}

class SplashPage extends StatefulWidget {
  @override
  SplashPageState createState() => SplashPageState();
}

class SplashPageState extends State<SplashPage> {

  void navigationToNextPage() {
    Navigator.pushNamed(context, '/home');
  }

  startSplashScreenTimer() async {
    var _duration = new Duration(seconds: 5);
    return new Timer(_duration, navigationToNextPage);
  }

  @override
  void initState() {
    super.initState();
    startSplashScreenTimer();
  }

  @override
  Widget build(BuildContext context) {

    SystemChrome.setEnabledSystemUIOverlays([]);

    return Container(
        child: new Image.asset('images/banner.png', fit: BoxFit.fill));
  }
}

所以我需要用颤振从两者中删除默认启动画面

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您可以通过忽略添加启动器图标来做到这一点。

    在 android 中转到 app -> main -> res -> drawable -> launch_background.xml 并保持如下:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@android:color/white" />    
        <!-- <item>
            <bitmap
                android:gravity="center"
                android:src="@mipmap/ic_launcher" />
        </item> -->
    </layer-list>
    

    【讨论】:

      【解决方案2】:

      默认启动画面不能单独使用 Dart/Flutter 覆盖。它们是在 Flutter 运行时初始化时由原生 Android/iOS 上下文显示的控件。因此,您在 Flutter 中创建的任何闪屏小部件都会在默认闪屏之后显示。 (即使你完全删除了默认的启动图像,在 Flutter 完成加载之前,应用程序在屏幕上仍然是空白的,这是一个糟糕的设计。)

      有关于如何更改默认启动画面here 的说明。如果您精通原生 Android 或 iOS 开发,您可以更进一步,而不仅仅是一个简单的图像。

      【讨论】:

      • 谢谢,那么如何为 ios 和 android 添加完全固定高度和宽度 100% 的图像
      • @MikelTawfik 我不记得了,但启动画面是一个非常简单的 Android 控件和 iOS 故事板,因此通过 Google 应该很容易找到它。也就是说,我不建议让您的初始屏幕 100% 填满屏幕,因为手机屏幕有各种形状和大小,因此在一部手机上看起来不错的图像在另一部手机上看起来会被拉伸和扭曲。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 2018-01-02
      相关资源
      最近更新 更多