Flutter - Change status bar color whithout AppBar

Viewed 1905

How to change status bar color whithout AppBar ?

my snippet code :

 @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiOverlayStyle.light,
        child: BodyWidget(),
      ),//
    );
  }
4 Answers

Hope this will help you

void main() {
  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(
      statusBarColor: Colors.red,
    ),
  );
  runApp(MyApp());
}

this work for me

@override 
Widget build(BuildContext context) {
return Scaffold(
  body: AnnotatedRegion<SystemUiOverlayStyle>(
    value: SystemUiOverlayStyle.light,
    child: BodyWidget(),
  ),//
);
}

Another effective way this can be done:

class MyWidget extends StatelessWidget {
  const MyWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle(
        statusBarColor: Colors.red,
        systemNavigationBarColor: Colors.red,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarIconBrightness: Brightness.dark,
      ),
      child: Scaffold(),
    );
  }
}

I use one general SafeArea in MaterialApp for all pages.

go to your MaterialApp Widget and change it like below code:

MaterialApp(
   builder: (context, child) {
      return Container(
         color: Colors.red, // your custom color
         child: SafeArea(child: child!)); },
// other material-app parameters...
),
Related