Это код, который я использовал для переключения между темным и светлым режимами. Все работает нормально, но цвет панели навигации и строки состояния не меняется автоматически, когда мое поддерево виджета содержит «Панель приложения Sliver».
Вот предварительный просмотр
PS: как только я удаляю панель приложений Sliver, все работает нормально
.
Код, который я использовал для переключения между темами.
if (MediaQuery.of(context).platformBrightness == Brightness.light) {
setState(() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
statusBarColor: Color(0xDCDCDCDC).withOpacity(1),
statusBarIconBrightness: Brightness.dark,
systemNavigationBarColor: Color(0xFAFAFAFA),
systemNavigationBarIconBrightness: Brightness.dark,
));
});
}
else {
setState(() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Color(0x000).withOpacity(1),
statusBarIconBrightness: Brightness.light,
systemNavigationBarColor: Colors.black.withAlpha(234),
systemNavigationBarIconBrightness: Brightness.light,
));
});
}
.
Код, который я использовал для панели приложений Sliver
class _HomeScreen extends State<HomeScreen>{
@override
Widget build(BuildContext context) {
return CustomScrollView(
physics: BouncingScrollPhysics(),
slivers: <Widget>[
SliverAppBar(
title: Text(
"Home",
style: Theme.of(context).textTheme.title.copyWith(fontWeight: FontWeight.w600),
),
floating: true,
backgroundColor: Theme.of(context).primaryColorDark,
elevation: 3,
forceElevated: true,
leading: Padding(
padding: EdgeInsets.only(
left: 16,
top: 10,
bottom: 10
),
child: ClipOval(
clipper: ProfileClipper(),
child: Image.network(
'https://images.unsplash.com/photo-1511447333015-45b65e60f6d5?ixlib=rb-1.2.1&w=1000&q=80',
fit: BoxFit.cover,
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent loadingProgress) {
if (loadingProgress == null)
return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes
: null,
),
);
},
),
),
),
actions: <Widget>[
Padding(
padding: EdgeInsets.only(
right: 8
),
child: IconButton(
icon: Icon(
Icons.more_vert
),
onPressed: () {},
),
)
],
),
],
);
}
}