import 'package:flutter/material.dart'; import 'package:kulinar_app/constants.dart'; import 'package:kulinar_app/views/info_view.dart'; import 'package:kulinar_app/views/main_view.dart'; import 'package:kulinar_app/views/vote_view.dart'; import 'package:kulinar_app/views/week_view.dart'; import 'package:kulinar_app/views/shoplist_view.dart'; import 'package:kulinar_app/views/settings_view.dart'; import 'package:kulinar_app/views/favorites_view.dart'; import 'package:kulinar_app/models/data/settings_data_class.dart'; import 'package:kulinar_app/widgets/page_route_transitions.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class CustomDrawer extends StatefulWidget { const CustomDrawer({Key? key, required this.initialIndex}) : super(key: key); final int initialIndex; @override CustomDrawerState createState() => CustomDrawerState(); } class CustomDrawerState extends State { int? _index; @override void initState() { super.initState(); _index = widget.initialIndex; } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { return Drawer( child: Column( children: [ Expanded( child: Column( children: [ _buildDrawerHeader(), _buildDrawerItem(0, Icons.receipt_rounded, AppLocalizations.of(context)!.category1, () { _navigateTo(const MainView(), 0); }), _buildDrawerItem(1, Icons.favorite_rounded, AppLocalizations.of(context)!.category4, () { _navigateTo(const FavoritesView(), 1); }), _buildDrawerItem(2, Icons.calendar_today_rounded, AppLocalizations.of(context)!.category5, () { _navigateTo(const WeekView(), 2); }), _buildDrawerItem(3, Icons.how_to_vote_rounded, AppLocalizations.of(context)!.category6, () { _navigateTo(const VoteView(), 3); }), _buildDrawerItem(4, Icons.shopping_cart_rounded, AppLocalizations.of(context)!.category7, () { _navigateTo(const ShoplistView(), 4); }), ], ), ), _buildDrawerItem(5, Icons.settings_rounded, AppLocalizations.of(context)!.category8, () { _navigateTo(const SettingsView(), 5); }), _buildDrawerItem(6, Icons.info_rounded, AppLocalizations.of(context)!.category9, () { _navigateTo(const InfoView(), 6); }), ], ), ); } Widget _buildDrawerHeader() { return const SizedBox( width: double.infinity, child: DrawerHeader( margin: EdgeInsets.zero, decoration: BoxDecoration(color: cPrimaryColor), child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( padding: EdgeInsets.only(bottom: 12.0), child: Icon( Icons.restaurant_menu_rounded, color: cIconColor, size: 100.0, ), ), ], ), ), ); } Widget _buildDrawerItem(int index, IconData icon, String title, Function callback) { Color color = cPassiveDrawerColor; if (index == _index) { color = cPrimaryColor; } if ((index == 2 || index == 3) && SettingsData.settings["serverURL"] == "") return Container(); return ListTile( leading: Icon(icon, color: color), title: Text(title, style: cDrawerTextStyle.copyWith(color: color)), onTap: () { callback(); }, ); } void _navigateTo(Widget route, int index) async { _index = index; Navigator.pop(context); await Navigator.pushReplacement( context, FadeRoute(child: route), ); } }