None of the given answers worked for me and I figured out something very important: you have to add the property extendBody: true
If true, and bottomNavigationBar or persistentFooterButtons is specified, then the body extends to the bottom of the Scaffold, instead of only extending to the top of the bottomNavigationBar or the persistentFooterButtons.
This property is often useful when the bottomNavigationBar has a non-rectangular shape, like CircularNotchedRectangle, which adds a FloatingActionButton sized notch to the top edge of the bar. In this case specifying extendBody: true ensures that that scaffold's body will be visible through the bottom navigation bar's notch
along with backgroundColor: Color(0x00ffffff),
.
NB: color with 0x is hexadecimal ARGB value (0xAARRGGBB), so 00 before the ffffff means maximum transparency, you can play to increase opacity by increasing the 00 up to ff (255 in hexadecimal).
Full code example:
import 'package:flutter/material.dart';
class NavigationBar extends StatefulWidget {
static int _selectedIndex = 0;
@override
NavigationBarState createState() => NavigationBarState();
}
class NavigationBarState extends State<NavigationBar> {
void _onItemTapped(int index) {
setState(() {
NavigationBar._selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
elevation: 0, // to get rid of the shadow
currentIndex: NavigationBar._selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
backgroundColor: Color(0x00ffffff), // transparent, you could use 0x44aaaaff to make it slightly less transparent with a blue hue.
type: BottomNavigationBarType.fixed,
unselectedItemColor: Colors.blue,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.grade),
label: 'Level',
),
BottomNavigationBarItem(
icon: Icon(Icons.notifications),
label: 'Notification',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'Achievements',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
),
]
);
}
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
Then where your have the MaterialApp return:
return MaterialApp(
home: Scaffold(
extendBody: true, // very important as noted
bottomNavigationBar: NavigationBar(), // here you make use of the transparent bar.
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: ExactAssetImage("assets/background.png"), // because if you want a transparent navigation bar I assume that you have either a background image or a background color. You need to add the image you want and also authorize it in pubspec.yaml
fit: BoxFit.fill
),
),
child: Container(
// the body of your app
),
),
),
);
}
}
I hope it will help.