如何使用注释区域更改状态栏颜色?



我想使用AnnotatedRegion更改状态栏的颜色,我从这个答案中得到了以下代码,但它对状态栏颜色没有影响。

AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.white),
child: Scaffold(
appBar: AppBar(
title: Text('Annotated Region'),
),
body: Center(
child:
Text('Status Bar!'),
),
),
)

若要快速开始使用此代码,可以使用此 Github 存储库。

如果您检查应用栏的代码,您将看到它使用自己的注释区域

final SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark;
return Semantics(
container: true,
child: AnnotatedRegion<SystemUiOverlayStyle>(
value: overlayStyle,
child: Material(
color: widget.backgroundColor
?? appBarTheme.color
?? theme.primaryColor,
elevation: widget.elevation
?? appBarTheme.elevation
?? _defaultElevation,
shape: widget.shape,
child: Semantics(
explicitChildNodes: true,
child: appBar,
),
),
),
);

要覆盖应用栏的效果,您需要用安全区域包裹您的脚手架,然后您将看到您自己的注释区域的更改

return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.white),
child: SafeArea(
child: Scaffold(
primary: false,
appBar: AppBar(
title: Text('Annotated Region'),
),
body: Center(
child: Text('Status Bar!'),
),
)
)
);

最新更新