flutter去除隐藏标题栏

发布时间 2023-12-19 14:31:45作者: 鲤斌

 使用 SystemChrome 类来控制系统 UI 元素的显示和隐藏 

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // 隐藏状态栏和导航栏
    SystemChrome.setEnabledSystemUIOverlays([]);

    return MaterialApp(
      title: 'Flutter App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

将 AppBar 的 automaticallyImplyLeading 属性设置为 false,即可隐藏左上角的返回箭头

appBar: AppBar(
  title: Text('My App'),
  automaticallyImplyLeading: false, // 隐藏返回箭头
),