I'm trying to have a background image on my Flutter app but I have not been able to make it so far. I have the following structure:
- AppBar with 2 tabs
- Some content inside each Tab
I have achieved this with the following code:
@override
Widget build(BuildContext context) {
return SafeArea(
child: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
elevation: 0,
bottom: const TabBar(
indicatorColor: Colors.red,
tabs: [
Tab(text: 'First Tab'),
Tab(text: 'Second Tab'),
],
),
title: const Text('First Tab'),
),
body: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/tree.jpg"),
fit: BoxFit.cover,
),
),
child: const TabBarView(
children: [
HomeScreen(), // contains the card with some text etc.
Icon(Icons.directions_transit),
],
),
),
),
),
);
}
I read that to make the AppBar transparent and have the same background image, I should add the following:
- To the Scaffold:
extendBodyBehindAppBar: true
- To the AppBar:
backgroundColor: Colors.transparent
But when I add them, the content inside the Tab slides under the AppBar tabs like so:
What I want to achieve is keeping them the same as the first picture and having the AppBar transparent.
Any suggestions on how to fix this or any other solution is welcome.