美文网首页Flutter中文社区FlutterFlutter圈子
flutter 配置 IOS 13 暗黑模式时 Status b

flutter 配置 IOS 13 暗黑模式时 Status b

作者: 沫toghayn丶in | 来源:发表于2019-10-17 13:51 被阅读0次

最近用 flutter 开发一个项目,在手机升到 ios 13 ,系统使用暗黑模式之后, 状态栏字体颜色一直是白色的,官方目前还没有适配完全, 在 github 上查了下,找到了临时解决方案
首先 在 Info.plist 文件里面 设置 View controller based status bar appearance 字段为 yes,

然后在 AppDelegate 文件里面 最下面贴上如下代码

let kOverlayStyleUpdateNotificationName = "io.flutter.plugin.platform.SystemChromeOverlayNotificationName"
let kOverlayStyleUpdateNotificationKey = "io.flutter.plugin.platform.SystemChromeOverlayNotificationKey"

extension FlutterViewController {
    private struct StatusBarStyleHolder {
        static var style: UIStatusBarStyle = .default
    }
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(appStatusBar(notification:)),
            name: NSNotification.Name(kOverlayStyleUpdateNotificationName),
            object: nil
        )
    }

    open override var preferredStatusBarStyle: UIStatusBarStyle {
        return StatusBarStyleHolder.style
    }
    
    @objc private func appStatusBar(notification: NSNotification) {
        guard
            let info = notification.userInfo as? Dictionary<String, Any>,
            let statusBarStyleKey = info[kOverlayStyleUpdateNotificationKey] as? Int
        else {
            return
        }
        
        if #available(iOS 13.0, *) {
            StatusBarStyleHolder.style = statusBarStyleKey == 0 ? .darkContent : .lightContent
        } else {
            StatusBarStyleHolder.style = statusBarStyleKey == 0 ? .default : .lightContent
        }
        
        setNeedsStatusBarAppearanceUpdate()
    }
}

相关文章

  • flutter 配置 IOS 13 暗黑模式时 Status b

    最近用 flutter 开发一个项目,在手机升到 ios 13 ,系统使用暗黑模式之后, 状态栏字体颜色一直是白色...

  • macOS 暗黑模式

    之前写了《iOS 13下暗黑(深色)模式的配置[https://www.jianshu.com/p/b77a876...

  • 暗黑模式开发

    iOS13暗黑模式适配(项目开发版) iOS 13 DarkMode 暗黑模式 IOS 暗黑模式适配---基础适配

  • ios13适配不断更新

    1. 暗黑模式 iOS13使用暗黑模式时,UIView默认背景色会变成暗黑色。适配暗黑模式的工作量较大,改为强制使...

  • iOS13 适配总结

    1. 暗黑模式 iOS13使用暗黑模式时,UIView默认背景色会变成暗黑色。适配暗黑模式的工作量较大,改为强制使...

  • 自己适配iOS13解决的问题总结

    自己适配iOS13解决的问题总结 1.暗黑模式Dark Mode iOS 13 推出暗黑模式,UIView默认背景...

  • uni-app做iOS的夜间模式

    iOS13适配暗黑模式/夜间模式/深色模式/暗黑主题(DarkMode)问题:1.监听Android深色或浅色模式...

  • iOS13 暗黑模式适配

    iOS13 暗黑模式适配,代码设置主题模式. AppDelegate中设置主题模式 UINavigationCon...

  • iOS高德地图适配暗黑模式

    iOS13以后iOS开发者讨论最大的应该就是暗黑模式了,我自己最近也在加班加点地为公司所有iOS项目适配暗黑模式,...

  • iOS:暗黑模式适配

    简介:iOS13苹果推出的暗黑模式,在去年苹果已经声明必须适配暗黑模式否则会下架。网上有很多好的文章来适配暗黑模式...

网友评论

    本文标题:flutter 配置 IOS 13 暗黑模式时 Status b

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