I need to change the brightness to dark(status bar to be in the dark mode) on scrolling the sliverappbar and pinned equal to true, when it is pinned the status background is white, so I need the status bar to be black, I hop you got what I need, please check the screenshot
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
CustomScrollView(
primary: true,
shrinkWrap: false,
slivers: <Widget>[
SliverAppBar(
pinned: true,
expandedHeight: 250,
elevation: 0,
backgroundColor: Colors.white,
I have created a program to please check it
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() async {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(),
darkTheme: ThemeData.dark(),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
ScrollController? _scrollController;
bool lastStatus = true;
double height = 200;
@override
void initState() {
super.initState();
_scrollController = ScrollController()..addListener(_scrollListener);
}
@override
void dispose() {
_scrollController?.removeListener(_scrollListener);
_scrollController?.dispose();
super.dispose();
}
void _scrollListener() {
if (_isShrink != lastStatus) {
setState(() {
lastStatus = _isShrink;
});
}
}
bool get _isShrink {
return _scrollController!.hasClients &&
_scrollController!.offset > (height - kToolbarHeight);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
controller: _scrollController,
slivers: [
SliverAppBar(
pinned: true,
expandedHeight: 300,
flexibleSpace: LayoutBuilder(builder: (context, constraints) {
//top = constraints.biggest.height;
return FlexibleSpaceBar(
title: const Text('Available seats'),
background: Image.network(
'https://r-cf.bstatic.com/images/hotel/max1024x768/116/116281457.jpg',
fit: BoxFit.fitWidth,
),
);
}),
systemOverlayStyle: SystemUiOverlayStyle(
statusBarIconBrightness:
_isShrink ? Brightness.dark : Brightness.light,
),
),
SliverList(
delegate: SliverChildListDelegate(
[
...List.generate(
20,
(index) => ListTile(
title: Text('index ${index.toString()}'),
),
)
],
),
)
],
),
);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.