When I scroll down in homepage the appbar color darkens but when i click any other tab the color stays same. I want the color to be the default appbar color when changed to new tab.
When not scrolled
When scrolled
When changed to another tab
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
int currentIndex = 0;
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('flutter app'),
),
body: IndexedStack(
index: currentIndex,
children: [
ListView.builder(
itemCount: 10,
itemBuilder: (ctx, index) {
return const Placeholder(
fallbackHeight: 200,
);
},
),
const Center(child: Text('search')),
const Center(child: Text('user')),
],
),
bottomNavigationBar: NavigationBar(
selectedIndex: currentIndex,
destinations: const [
NavigationDestination(icon: Icon(Icons.home), label: 'home'),
NavigationDestination(icon: Icon(Icons.search), label: 'search'),
NavigationDestination(icon: Icon(Icons.person), label: 'user'),
],
onDestinationSelected: (index) {
setState(
() {
currentIndex = index;
},
);
},
),
),
);
}
}
tried:
scrolledUnderElevation: 0
and surfaceTintColor: Colors.transparent
but it still remains a little dark.
This is what it should look like
2
Answers
weird, But you can definitely try to force transparency in the
AppBar
:you can get ride of this using
backgroundColor
andsurfaceTintColor
like this:or you can change
forceMaterialTransparency
to true as answered by A-E like this:read-more