需要手动导包
import 'dart:io';
import 'package:flutter/services.dart';
需要注意的是:
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:flutter/services.dart';
//首页
void main() {
runApp(new MyApp());
//判断如果是Android版本的话 设置Android状态栏透明沉浸式
if (Platform.isAndroid) {
//沉浸式状态栏
//写在组件渲染之后,是为了在渲染后进行设置赋值,覆盖状态栏,写在渲染之前对MaterialApp组件会覆盖这个值。
SystemUiOverlayStyle systemUiOverlayStyle =
SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "我只是显示而已",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Color(0xff1594FA)
),
home: MyHomePage()
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("我是标题"),
centerTitle: true,),
body: Center(
child: Text("居中"),
),
);
}
}
一张是Android透明沉浸式状态栏效果图,另外一张是按了home键的效果图
0CD09B5222EF8F35988672192BF474A9.png
B73BC1DB07DB434AFA750FAF117D0160.jpg