- Edited
Hi guys,
I’ve created a simple BottomNavigationBar with 4 items. By clicking on the first item I want to display a Sidebar (drawer). Unfortunately, the drawer is not showing and I can’t figure out why but I’m pretty new to flutter…
This is my code:
HomePage:
class HomePageLoggedIn extends StatefulWidget {
const HomePageLoggedIn({Key? key}) : super(key: key);
@override
State<HomePageLoggedIn> createState() => _HomePageLoggedInState();
}
class _HomePageLoggedInState extends State<HomePageLoggedIn> {
int _currentIndex = 3;
@override
Widget build(BuildContext context) {
return MultiBlocListener(
listeners: [
BlocListener<AuthBloc, AuthState>(listener: (context, state) {
//Wenn ich unauthenticated bin, dann sehe ich die SignUpPage, also das Login Form
if (state is AuthStateUnauthenticated) {
AutoRouter.of(context).push(const SignUpPageRoute());
}
})
],
child: Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () {
BlocProvider.of<AuthBloc>(context).add(SignOutPressedEvent());
},
icon: const Icon(Icons.exit_to_app),
),
title: const Text("MonthlyBudget")),
body: IndexedStack(
index: _currentIndex,
children: const [
AccountPage(),
IncomePage(),
TransactionPage(),
BudgetPage()
],
),
bottomNavigationBar: BottomNavigationBar(
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
currentIndex: _currentIndex,
unselectedItemColor: Colors.grey,
selectedItemColor: Colors.white,
backgroundColor: Theme.of(context).appBarTheme.backgroundColor,
showUnselectedLabels: true,
type: BottomNavigationBarType.fixed,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.settings), label: "Account"),
BottomNavigationBarItem(icon: Icon(Icons.euro), label: "Beträge"),
BottomNavigationBarItem(
icon: Icon(Icons.compare_arrows), label: "Transaktionen"),
BottomNavigationBarItem(
icon: Icon(Icons.account_balance), label: "Budget"),
],
),
),
);
}
}
AccountPage:
import 'package:flutter/material.dart';
class AccountPage extends StatelessWidget {
const AccountPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
drawer: Drawer(
backgroundColor: Colors.white,
child: ListView(
children: <Widget>[
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text('Drawer Header'),
),
ListTile(
title: const Text('Item 1'),
onTap: () {
// Update the state of the app.
// ...
},
),
ListTile(
title: const Text('Item 2'),
onTap: () {
// Update the state of the app.
// ...
},
),
],
),
),
);
}
}