diff options
Diffstat (limited to 'lib/widgets/custom_drawer_widget.dart')
-rw-r--r-- | lib/widgets/custom_drawer_widget.dart | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/lib/widgets/custom_drawer_widget.dart b/lib/widgets/custom_drawer_widget.dart new file mode 100644 index 0000000..3fd8c2e --- /dev/null +++ b/lib/widgets/custom_drawer_widget.dart @@ -0,0 +1,129 @@ +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 { + CustomDrawer({Key? key, required this.initalIndex}) : super(key: key); + + final int initalIndex; + + @override + _CustomDrawerState createState() => _CustomDrawerState(); +} + +class _CustomDrawerState extends State<CustomDrawer> { + int? _index; + + @override + void initState() { + super.initState(); + _index = widget.initalIndex; + } + + @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(MainView(), 0); + }), + _buildDrawerItem(1, Icons.favorite_rounded, AppLocalizations.of(context)!.category4, () { + _navigateTo(FavoritesView(), 1); + }), + _buildDrawerItem(2, Icons.calendar_today_rounded, AppLocalizations.of(context)!.category5, () { + _navigateTo(WeekView(), 2); + }), + _buildDrawerItem(3, Icons.how_to_vote_rounded, AppLocalizations.of(context)!.category6, () { + _navigateTo(VoteView(), 3); + }), + _buildDrawerItem(4, Icons.shopping_cart_rounded, AppLocalizations.of(context)!.category7, () { + _navigateTo(ShoplistView(), 4); + }), + ], + ), + ), + _buildDrawerItem(5, Icons.settings_rounded, AppLocalizations.of(context)!.category8, () { + _navigateTo(SettingsView(), 5); + }), + _buildDrawerItem(6, Icons.info_rounded, AppLocalizations.of(context)!.category9, () { + _navigateTo(InfoView(), 6); + }), + ], + ), + ); + } + + Widget _buildDrawerHeader() { + return SizedBox( + width: double.infinity, + child: DrawerHeader( + margin: EdgeInsets.zero, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 12.0), + child: Icon( + Icons.restaurant_menu_rounded, + color: cIconColor, + size: 100.0, + ), + ), + ], + ), + decoration: BoxDecoration(color: cPrimaryColor), + ), + ); + } + + 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), + ); + } +} |