美文网首页Flutter
Flutter沉浸式状态栏

Flutter沉浸式状态栏

作者: 月未雪 | 来源:发表于2019-11-04 15:06 被阅读0次

Flutter沉浸式状态栏

1.SystemUiOverlayStyle

    dark :状态栏字体黑色
    light:状态栏字体白色

2.通过Appbar 设置状态栏的字体颜色
    appBar: AppBar(brightness: Brightness.light)

3.设置状态栏的的颜色,与字体的颜色
     static setBarStatus(bool isDarkIcon,
          {Color color: Colors.transparent}) async {
        if (Platform.isAndroid) {
          if (isDarkIcon) {
            SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
                statusBarColor: color, statusBarIconBrightness: Brightness.dark);
            SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
          } else {
            SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
                statusBarColor: color, statusBarIconBrightness: Brightness.light);
            SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
          }
        }
      }

4.自定义toolbar:

     return AnnotatedRegion<SystemUiOverlayStyle>(
              value: SystemUiOverlayStyle.dark,
              child: body,
            );

     class ToolAppBar extends StatelessWidget implements PreferredSizeWidget {


      Widget build(BuildContext context) {
        return Container();

      }

      //通过preferredSize 自已头部 appbar
      Size get preferredSize => Size.fromHeight(248+kToolbarHeight);
    }

5.Flutter SafeArea

     使用SafeArea能很好的解决刘海,不规则屏幕的显示问题。

相关文章

网友评论

    本文标题:Flutter沉浸式状态栏

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