Skip to content

Commit

Permalink
Update bottom navbar design
Browse files Browse the repository at this point in the history
  • Loading branch information
Process-ing committed Jan 18, 2024
1 parent 15e9186 commit e400ec6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
27 changes: 13 additions & 14 deletions uni/lib/utils/navbar_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@ import 'package:flutter/material.dart';

enum NavbarItem {
navPersonalArea(
'Área Pessoal',
Icons.home_outlined,
['Área Pessoal'],
['area'],
),
navStudentArea(
'Área do Estudante',
navAcademicPath(
Icons.school_outlined,
['Horário', 'Exames', 'Cadeiras'],
['horario', 'exames', 'cadeiras'],
),
navMap(
'Mapa e Transportes',
Icons.map_outlined,
['Autocarros', 'Locais'],
navTransports(
Icons.directions_bus_filled_outlined,
['autocarros']
),
navFaculty(
'Faculdade',
Icons.domain_outlined,
['Restaurantes', 'Calendário', 'Biblioteca', 'Úteis'],
['locais', 'biblioteca', 'uteis'],
),
navRestaurants(
Icons.local_cafe_outlined,
['restaurantes'],
);

const NavbarItem(this.label, this.icon, this.routes);
const NavbarItem(this.icon, this.routes);

final String label;
final IconData icon;
final List<String> routes;
// TODO(Process-ing): Transform into single route when the new pages are done

BottomNavigationBarItem toBottomNavigationBarItem() {
return BottomNavigationBarItem(
icon: Icon(icon),
label: label,
label: '',
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:uni/utils/drawer_items.dart';
import 'package:uni/utils/navbar_items.dart';

class AppBottomNavbar extends StatefulWidget {
Expand All @@ -21,7 +22,7 @@ class AppBottomNavbarState extends State<AppBottomNavbar> {

String _getCurrentRoute() =>
ModalRoute.of(widget.parentContext)!.settings.name == null
? NavbarItem.values.toList()[0].label
? DrawerItem.navPersonalArea.title
: ModalRoute.of(widget.parentContext)!.settings.name!.substring(1);

int _getCurrentIndex() {
Expand All @@ -33,15 +34,15 @@ class AppBottomNavbarState extends State<AppBottomNavbar> {
}
}

return NavbarItem.navPersonalArea.index;
return -1;
}

void _onItemTapped(int index) {
final prev = _getCurrentRoute();
final item = NavbarItem.values[index];
final key = item.routes.isNotEmpty
? item.routes[0]
: NavbarItem.navPersonalArea.routes[0];
: DrawerItem.navPersonalArea.title;

if (prev != key) {
Navigator.of(context).pop();
Expand All @@ -51,11 +52,18 @@ class AppBottomNavbarState extends State<AppBottomNavbar> {

@override
Widget build(BuildContext context) {
final currentIndex = _getCurrentIndex();
return BottomNavigationBar(
items: navbarItems,
currentIndex: _getCurrentIndex(),
selectedItemColor: Theme.of(context).primaryColor,
type: currentIndex == -1 ? BottomNavigationBarType.fixed
: BottomNavigationBarType.shifting,
currentIndex: currentIndex == -1 ? 0 : currentIndex,
selectedItemColor: currentIndex == -1
? Theme.of(context).colorScheme.onSurface
: Theme.of(context).primaryColor,
unselectedItemColor: Theme.of(context).colorScheme.onSurface,
showSelectedLabels: false,
showUnselectedLabels: false,
onTap: _onItemTapped,
);
}
Expand Down

0 comments on commit e400ec6

Please sign in to comment.