Flutter -更改状态栏颜色而不使用AppBar

ar5n3qh5  于 2023-05-23  发布在  Flutter
关注(0)|答案(3)|浏览(151)

如何改变状态栏的颜色没有AppBar?
我的代码片段:

@override
  Widget build(BuildContext context) {

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

emeijp431#

希望这对你有帮助

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

brtdzjyr2#

这个工作对我来说

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

dxxyhpgq3#

另一种有效的方法是:

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(),
    );
  }
}

相关问题