{"id":157,"date":"2022-12-01T23:50:56","date_gmt":"2022-12-01T15:50:56","guid":{"rendered":"https:\/\/www.adaycode.com\/dev\/?p=157"},"modified":"2022-12-01T23:50:59","modified_gmt":"2022-12-01T15:50:59","slug":"how-order-of-safearea-affect-status-bar-in-flutter","status":"publish","type":"post","link":"https:\/\/www.adaycode.com\/dev\/how-order-of-safearea-affect-status-bar-in-flutter\/","title":{"rendered":"How Order of SafeArea affect Status Bar in Flutter"},"content":{"rendered":"\n<p>People may not notice the order of the <mark style=\"background-color:#dddddd\" class=\"has-inline-color\">SafeArea<\/mark> widget has a prominent impact on the status bar which shows the clock and battery level.<\/p>\n\n\n\n<p><mark style=\"background-color:#dddddd\" class=\"has-inline-color\">SafeArea<\/mark> widget will try its best to avoid influence (such as round corners, status bar, notch) by the operating system. Therefore, it will indent its child by enough padding to avoid the top status bar.<\/p>\n\n\n\n<p>If you are using <mark style=\"background-color:#dddddd\" class=\"has-inline-color\">Scaffold<\/mark> with an <mark style=\"background-color:#dddddd\" class=\"has-inline-color\">AppBar<\/mark>, there is no need to wrap the <mark style=\"background-color:#dddddd\" class=\"has-inline-color\">Scaffold<\/mark> in a <mark style=\"background-color:#dddddd\" class=\"has-inline-color\">SafeArea<\/mark>. Flutter will calculate the correct spacing at the top screen and the background colour of the status bar will be the same as the AppBar&#8217;s.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"455\" height=\"212\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.adaycode.com\/dev\/wp-content\/uploads\/2022\/12\/flutter_without_safearea.jpg?resize=455%2C212&#038;ssl=1\" alt=\"\" class=\"wp-image-159\" srcset=\"https:\/\/i0.wp.com\/www.adaycode.com\/dev\/wp-content\/uploads\/2022\/12\/flutter_without_safearea.jpg?w=455&amp;ssl=1 455w, https:\/\/i0.wp.com\/www.adaycode.com\/dev\/wp-content\/uploads\/2022\/12\/flutter_without_safearea.jpg?resize=300%2C140&amp;ssl=1 300w\" sizes=\"auto, (max-width: 455px) 100vw, 455px\" \/><figcaption class=\"wp-element-caption\">Without SafeArea<\/figcaption><\/figure>\n\n\n\n<p>On the other hand, if you wrap the the <mark style=\"background-color:#dddddd\" class=\"has-inline-color\">Scaffold<\/mark> in a <mark style=\"background-color:#dddddd\" class=\"has-inline-color\">SafeArea<\/mark>, the background of the status bar will become the black (system&#8217;s default value), not the AppBar&#8217;s background colour.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"455\" height=\"212\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.adaycode.com\/dev\/wp-content\/uploads\/2022\/12\/flutter_with_safearea.png?resize=455%2C212&#038;ssl=1\" alt=\"\" class=\"wp-image-160\" srcset=\"https:\/\/i0.wp.com\/www.adaycode.com\/dev\/wp-content\/uploads\/2022\/12\/flutter_with_safearea.png?w=455&amp;ssl=1 455w, https:\/\/i0.wp.com\/www.adaycode.com\/dev\/wp-content\/uploads\/2022\/12\/flutter_with_safearea.png?resize=300%2C140&amp;ssl=1 300w\" sizes=\"auto, (max-width: 455px) 100vw, 455px\" \/><figcaption class=\"wp-element-caption\">Scaffold wrapped with SafeArea<\/figcaption><\/figure>\n\n\n\n<p>Here is the code snippet:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" style=\"font-size:.875rem;--cbp-line-number-color:#d8dee9ff;--cbp-line-number-width:16.859375px;--cbp-line-highlight-color:rgba(201, 218, 248, 0.2);line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      debugShowCheckedModeBanner: false,\n      home: SafeArea(\n        child: Scaffold(\n          appBar: AppBar(\n            title: const Text('Welcome to Flutter'),\n          ),\n          body: const Center(\n            child: Text('Hello World'),\n          ),\n        ),\n      ), \/\/ SafeArea\n    );\n  }\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki\" style=\"background-color: #2e3440ff\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #81A1C1\">@override<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #8FBCBB\">Widget<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">build<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #8FBCBB\">BuildContext<\/span><span style=\"color: #D8DEE9FF\"> context) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">MaterialApp<\/span><span style=\"color: #D8DEE9FF\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">      debugShowCheckedModeBanner<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">false<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #D8DEE9FF\">      home<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">SafeArea<\/span><span style=\"color: #D8DEE9FF\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        child<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">Scaffold<\/span><span style=\"color: #D8DEE9FF\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">          appBar<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">AppBar<\/span><span style=\"color: #D8DEE9FF\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            title<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">Text<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #A3BE8C\">&#39;Welcome to Flutter&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">          )<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">          body<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">Center<\/span><span style=\"color: #D8DEE9FF\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            child<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">Text<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #A3BE8C\">&#39;Hello World&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">          )<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        )<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #D8DEE9FF\">      )<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">\/\/ SafeArea<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    )<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Unless you want the background colour of the status bar to follow the operating system&#8217;s default value rather than the AppBar&#8217;s colour, a <mark style=\"background-color:#dddddd\" class=\"has-inline-color\">Scaffold<\/mark> should not be wrapped with a <mark style=\"background-color:#dddddd\" class=\"has-inline-color\">SafeArea<\/mark>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>People may not notice the order of the SafeArea widget has a prominent impact on&#8230;<\/p>\n","protected":false},"author":2,"featured_media":162,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[16,9,6,5,13,15,11,22,42],"class_list":["post-157","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-flutter-tutorials","tag-android-development","tag-app-development","tag-dart","tag-flutter","tag-flutter-tutorial","tag-ios-development","tag-programming","tag-tip","tag-ui"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.adaycode.com\/dev\/wp-content\/uploads\/2022\/12\/flutter_safearea_featured.jpg?fit=1024%2C736&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/posts\/157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/comments?post=157"}],"version-history":[{"count":2,"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/posts\/157\/revisions"}],"predecessor-version":[{"id":161,"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/posts\/157\/revisions\/161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/media\/162"}],"wp:attachment":[{"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/media?parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/categories?post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.adaycode.com\/dev\/wp-json\/wp\/v2\/tags?post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}