statusBar为什么一直是白色的,看了代码也没啥不一致的

来源:12-6 代码优化实现Dark Mode适配

夏目鲸鱼

2021-06-13

代码如下

enum StatusStyle { LIGHT_CONTENT, DARK_CONTENT }
//可自定义样式的沉浸式导航栏

class NavigationBar extends StatefulWidget {
  final StatusStyle statusStyle;
  final Color color;
  final double height;
  final Widget child;

  const NavigationBar(
      {Key key,
      this.statusStyle = StatusStyle.DARK_CONTENT,
      this.color = Colors.white,
      this.height = 46,
      this.child})
      : super(key: key);
  @override
  _NavigationBarState createState() => _NavigationBarState();
}

class _NavigationBarState extends State<NavigationBar> {
  var _statusStyle;
  var _color;

  @override
  Widget build(BuildContext context) {
    var themeProvider = context.watch<ThemeProvider>();
    if (themeProvider.isDark()) {
      _color = HiColor.dark_bg;
      _statusStyle = StatusStyle.LIGHT_CONTENT;
    } else {
      _color = widget.color;
      _statusStyle = widget.statusStyle;
    }
    _statusBarInit();

    //状态栏高度
    var top = MediaQuery.of(context).padding.top;
    return Container(
      width: MediaQuery.of(context).size.width,
      height: top + widget.height,
      child: widget.child,
      padding: EdgeInsets.only(top: top),
      decoration: BoxDecoration(color: _color),
    );
  }

  void _statusBarInit() {
    //沉浸式状态栏样式
    changeStatusBar(color: _color, statusStyle: _statusStyle);
  }
}

写回答

1回答

CrazyCodeBoy

2021-06-15

在changeStatusBar方法中打个断点调试下,看_statusStyle的值是否符合预期,也可将这章的课程源码拉下来,运行下看看差异:https://git.imooc.com/coding-487/fa-theme



0
1
夏目鲸鱼
有个变量没引用到
2021-06-15
共1条回复

Flutter高级进阶实战-仿哔哩哔哩-掌握Flutter高阶技能

一次性掌握Flutter高阶技能+商业级复杂项目架构设计与开发方案

1723 学习 · 870 问题

查看课程