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

1. 隐藏顶部状态栏

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

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

SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);

2. 隐藏底部操作栏

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

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

SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);

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

  • 效果图:
  • 解决方案:
    增加依赖:
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<MyHomePage> {
  @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: <Widget>[
            Text(
              'Hello World!',
            ),
          ],
        ),
      ),
    );
  }
}

关注头条号,第一时间获取最新文章:

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页