0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Flutter】StatusBarの色変更をAndroidとiOS両方に対応させる

Posted at

問題点

こちらがよくあるStatusBarの色の変更方法だと思います。
しかし、この方法だとAndroidには反映されるものの、iOSには反映されません。

SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(
      statusBarColor: <任意のステータスバーの色>,
    ),
);

解決方法

カスタムAppBarを作成し、Stackを使ってStatusBarの高さ分のContainerをAppBarに被せる

class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  const CustomAppBar({super.key});

  @override
  Widget build(BuildContext context) {
    final statusBarHeight = MediaQuery.of(context).viewPadding.top;

    return Stack(
      children: [
        AppBar(),
        // StatusBarサイズの色付きContainer
        Container(
          width: double.infinity,
          height: statusBarHeight,
          color: <任意のステータスバーの色>,
        ),
      ],
    );
  }

  @override
  Size get preferredSize {
    return const Size.fromHeight(kToolbarHeight);
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?