How to change Status Bar and App Bar color in Flutter?

后端 未结 6 2043
后悔当初
后悔当初 2020-12-14 17:16

I\'m trying to change the color of system status bar to black. The configuration seems to be overridden by the AppBar class. I can achieve what I want by assigning theme: to

6条回答
  •  轮回少年
    2020-12-14 17:25

    I'm quite new to StackOverflow & I've never used Flutter however I have found this package that seems to make things relatively easy.

    Method 1: Using the package

    Once this is imported all you need to do is add this code fragment:

    try {
    await FlutterStatusbarcolor.setStatusBarColor(Colors.black);
    } on PlatformException catch (e) {
    print(e);
    }
    

    Replacing the parameter for the setStatusBarColor() should give you the desired result, a full list of colours can be found here.

    Method 2: Using default functions

    If this doesn't work / you don't want to add extra packages or libraries then perhaps this StackOverflow answer may help.

    It involves using a similar function to the above method: getWindow().setStatusBarColor() or getActivity().getWindow().setStatusBarColor()

    Replacing the parameter with the desired hex code from the same list as earlier may also result in a solution.

    Hope it works/helps!

提交回复
热议问题