如何进入全屏模式

时间:2018-05-21 07:49:49

标签: fullscreen flutter

我使用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,
      ),
    );
  }
}

4 个答案:

答案 0 :(得分:2)

Android上似乎有an issue。由于某些原因,它不会重新计算SafeArea

答案 1 :(得分:2)

这对我来说很完美:

  @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';

答案 2 :(得分:0)

设置resizeToAvoidBottomPadding:对Scaffold为false。

   return Scaffold(
      resizeToAvoidBottomPadding: false,
   );

答案 3 :(得分:0)

颤动 2.x:

  • 仍然有这个问题。
  • // resizeToAvoidBottomInset: false 不适合我。

我的解决方案:

  • Container.height = Get.height // 设置 max 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,
    );
  }
}