美文网首页flutter
Flutter 状态栏完美攻略,不要找了,都在这里了

Flutter 状态栏完美攻略,不要找了,都在这里了

作者: BeRicher | 来源:发表于2020-10-11 20:34 被阅读0次

本篇文章的前提是使用ScaffoldAppBar组件。

1. 沉浸式状态栏

Scaffold(
        extendBodyBehindAppBar: true,
        appBar: AppBar(
          toolbarHeight: 0,
        ),
        body: Container(color:Colors.red)
)

2. 状态栏的背景颜色

Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.transparent,
        ),
        body: Container(color:Colors.red)
)

3. 状态栏的文字颜色

Brightness.light文字黑色
Brightness.dark文字白色

Scaffold(
        appBar: AppBar(
          brightness: Brightness.light,
        ),
        body: Container(color:Colors.red)
)

4. 沉浸式状态栏下的安全区域

使用SafeArea

Scaffold(
        extendBodyBehindAppBar: true,
        appBar: AppBar(
          toolbarHeight: 0,
        ),
        body: SafeArea(child:Container(color:Colors.red))
)

5. Android机器的状态栏颜色改为透明

默认是带个遮罩的,完全去除:

void main() async {
   runApp(MaterialApp());
    SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(statusBarColor:Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}

要写在runApp(MaterialApp());后面。

相关文章

网友评论

    本文标题:Flutter 状态栏完美攻略,不要找了,都在这里了

    本文链接:https://www.haomeiwen.com/subject/zuxypktx.html