Flutter如何进入全屏模式

6
我使用setEnabledSystemUIOverlays来隐藏状态栏和虚拟按钮栏。

但屏幕顶部和底部会出现空白 (如照片所示):

Screen Photo

有人知道如何解决吗?

以下是我的代码:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  SystemChrome.setEnabledSystemUIOverlays([]);
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: "Test",
      home: new MyHomePage(title: "Test"),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;

  MyHomePage({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(title),
      ),
      body: new Container(
        color: Colors.red,
      ),
    );
  }
}

是的,我正在使用华硕平板电脑。这可能是原因吗? - 蔡旻袁
奇怪,这对我来说是有效的。 - Phuc Tran
在iOS上一切都很好,但在Android模拟器上仍然发生了这种情况。 - 蔡旻袁
你使用的SDK版本是什么?我正在使用最新的测试版。 - 蔡旻袁
你没看到空格吗? - 蔡旻袁
显示剩余9条评论
4个回答

7

这个IT技术对我非常完美地起作用:

  @override
  Widget build(BuildContext context) {

    // To make this screen full screen.
    // It will hide status bar and notch.
    SystemChrome.setEnabledSystemUIOverlays([]);

    // full screen image for splash screen.
    return Container(
            child: new Image.asset('assets/splash.png', fit: BoxFit.fill));
      }
    }

导入此

import 'package:flutter/services.dart';

7

将resizeToAvoidBottomPadding: false设置为Scaffold。

   return Scaffold(
      resizeToAvoidBottomPadding: false,
   );

2

在 Android 上似乎存在问题。由于某种原因,它不会重新计算SafeArea


0

Flutter 2.x:

  • 仍然存在这个问题。
  • // resizeToAvoidBottomInset: false 对我无效。

我的解决方案:

  • Container.height = Get.height // 设置 最大高度
  • Container.child.image.fit = BoxFit.fill // 使用此选项
  • flutter 2.2.0 下,这对我有效。

全屏页面示例:

  • 完整代码:

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:lottie/lottie.dart';


import '../controllers/splash_controller.dart';

class SplashScreenView extends GetView<SplashController> {
  final SplashController c = Get.find();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        /// key! fix full screen
        height: Get.height,

        ///
        child: Lottie.asset(
          /// image file:
          AppConfig.splash1,

          /// key! fix full screen
          fit: BoxFit.fill,

          ///
          controller: c.animationController,
          frameRate: FrameRate(60),
          repeat: true,

          ///
          delegates: LottieDelegates(
            text: (initialText) => 'test',
          ),

          onLoaded: (composition) {
            c.animationController..duration = composition.duration;
          },
        ),
      ),

      /// not work
      // resizeToAvoidBottomInset: false,
      backgroundColor: Colors.white,
    );
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接