Flutter隐藏顶部状态栏和底部操作栏

1. 隐藏顶部状态栏

  • 效果图:


    image
  • 解决方案:
    增加依赖:
import 'package:flutter/services.dart';

在最上层的Widget的build方法开头增加如下代码.

SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);

2. 隐藏底部操作栏

  • 效果图:


    image
  • 解决方案:
    增加依赖:
import 'package:flutter/services.dart';

在最上层的Widget的build方法开头增加如下代码.

SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);

3. 隐藏顶部状态栏和底部操作栏

  • 效果图:


    image
  • 解决方案:
    增加依赖:
import 'package:flutter/services.dart';

在最上层的Widget的build方法开头增加如下代码.

SystemChrome.setEnabledSystemUIOverlays([]);

完整代码

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
  @override
  Widget build(BuildContext context) {
    //显示底部栏(隐藏顶部状态栏)
//    SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
    //显示顶部栏(隐藏底部栏)
//    SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);
    //隐藏底部栏和顶部状态栏
    SystemChrome.setEnabledSystemUIOverlays([]);
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              'Hello World!',
            ),
          ],
        ),
      ),
    );
  }
}

你可能感兴趣的:(Flutter隐藏顶部状态栏和底部操作栏)