Flutter web status bar in iOS (Safari)
Asked Answered
W

3

9

I try to change the status bar in the safari browser, I search it and it was a lot's question about it but none of them fixed my issue. I tried change-status-bar-color and how-to-change-chrome-header-color.

enter image description here

This blue area is around iPhone's notches, and I want to change the color in the whole app.

thanks for your attention.

Waxler answered 4/2, 2022 at 18:8 Comment(0)
A
11

You want to change the value for theme-color. The default color you're seeing is defined in your web/manifest.json file.

You could also set it, for example to white for your light-theme and to black for your dark-theme, by adding following lines to your web/index.html:

<meta name="theme-color" media="(prefers-color-scheme: light)" content="#FFFFFF">
<meta name="theme-color" media="(prefers-color-scheme: dark)"  content="#000000">

You could also change it dynamically via dart:js by adding a script to your web/index.html:

<script>
  function setMetaThemeColor(color) {
      document.querySelector('meta[name="theme-color"]').setAttribute("content", color);
    }
</script>

Then call it via dart:js:

import 'package:flutter/material.dart';
import 'dart:js' as js;

extension ColorString on Color {
  String toHexString() {
    return '#${(value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}';
  }
}

void setMetaThemeColor(Color color) {
  js.context.callMethod("setMetaThemeColor", [color.toHexString()]);
}
Antiicer answered 14/3, 2022 at 20:57 Comment(2)
should be accepted. manifest.json didn't work for me (don't know why) but index.html config worked perfectly. Don't forget to clear safari cache or use private navigation to see changes quicklyAcme
Thanks this works. Any idea if it is possible to put this on Dart code instead?Hemelytron
G
3

Flutter 3.13.0

Status bar color can be changed based on SystemUiOverlayStyle.

Check out Proposal for more information: https://github.com/flutter/flutter/issues/123365

Check out Pull Request for more information: https://github.com/flutter/engine/pull/40599


  1. Using AppBar widget:

    Scaffold(
      appBar: AppBar(
        systemOverlayStyle: const SystemUiOverlayStyle(statusBarColor: Colors.red),
      ),
    )
    

  1. Using AnnotatedRegion:

    @override
    Widget build(BuildContext context) {
      return AnnotatedRegion<SystemUiOverlayStyle>(
        value: const SystemUiOverlayStyle(statusBarColor: Colors.red),
        child: ...,
      );
    }
    

  1. Call SystemChrome.setSystemUIOverlayStyle from your code:

    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(statusBarColor: Colors.red));
    

  1. Call SystemChrome.setSystemUIOverlayStyle inside build method:

    @override
    Widget build(BuildContext context) {
      SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(statusBarColor: Colors.red));
    
      return ...;
    }
    

Below Flutter 3.13.0


  1. Using MaterialApp.color property:

    @override
    Widget build(BuildContext context) {
      return const MaterialApp(
        color: Colors.red,
        home: ...,
      );
    }
    

  1. Using MaterialApp.theme.primaryColor property:

    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        theme: ThemeData.light().copyWith(primaryColor: Colors.red),
        home: ...,
      );
    }
    
Galle answered 26/4, 2023 at 16:29 Comment(0)
E
0

Please try to use the below code:

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.red,
));
Exasperate answered 4/2, 2022 at 19:34 Comment(2)
Thanks for your response, I checked it before and it's not working. it worked in the android browser but not in Safari.Waxler
can you make me understand the safari aspect very well? i try that code on ios n is workingExasperate

© 2022 - 2024 — McMap. All rights reserved.