Skip to content

Commit

Permalink
Merge branch 'ui/redesign' into feature/profile-card
Browse files Browse the repository at this point in the history
  • Loading branch information
vitormpp authored Feb 6, 2025
2 parents f2b0886 + 3a78367 commit 881f3e5
Show file tree
Hide file tree
Showing 30 changed files with 545 additions and 885 deletions.
2 changes: 1 addition & 1 deletion packages/uni_app/app_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0-beta.53+358
1.10.0-beta.55+360
2 changes: 1 addition & 1 deletion packages/uni_app/lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MessageLookup extends MessageLookupByLibrary {
'calendario': 'Calendar',
'biblioteca': 'Library',
'percurso_academico': 'Academic Path',
'transportes': 'Transports',
'mapa': 'Map',
'faculdade': 'Faculty',
'other': 'Other',
})}";
Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/lib/generated/intl/messages_pt_PT.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MessageLookup extends MessageLookupByLibrary {
'calendario': 'Calendário',
'biblioteca': 'Biblioteca',
'percurso_academico': 'Percurso Académico',
'transportes': 'Transportes',
'mapa': 'Mapa',
'faculdade': 'Faculdade',
'other': 'Outros',
})}";
Expand Down
4 changes: 2 additions & 2 deletions packages/uni_app/lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/uni_app/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
"@min_value_reference": {},
"multimedia_center": "Multimedia center",
"@multimedia_center": {},
"nav_title": "{title, select, horario{Schedule} exames{Exams} area{Personal Area} cadeiras{Course Units} autocarros{Buses} locais{Places} restaurantes{Restaurants} calendario{Calendar} biblioteca{Library} percurso_academico{Academic Path} transportes{Transports} faculdade{Faculty} other{Other}}",
"nav_title": "{title, select, horario{Schedule} exames{Exams} area{Personal Area} cadeiras{Course Units} autocarros{Buses} locais{Places} restaurantes{Restaurants} calendario{Calendar} biblioteca{Library} percurso_academico{Academic Path} mapa{Map} faculdade{Faculty} other{Other}}",
"@nav_title": {},
"news": "News",
"@news": {},
Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/lib/l10n/intl_pt_PT.arb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"@min_value_reference": {},
"multimedia_center": "Centro de multimédia",
"@multimedia_center": {},
"nav_title": "{title, select, horario{Horário} exames{Exames} area{Área Pessoal} cadeiras{Cadeiras} autocarros{Autocarros} locais{Locais} restaurantes{Restaurantes} calendario{Calendário} biblioteca{Biblioteca} percurso_academico{Percurso Académico} transportes{Transportes} faculdade{Faculdade} other{Outros}}",
"nav_title": "{title, select, horario{Horário} exames{Exames} area{Área Pessoal} cadeiras{Cadeiras} autocarros{Autocarros} locais{Locais} restaurantes{Restaurantes} calendario{Calendário} biblioteca{Biblioteca} percurso_academico{Percurso Académico} mapa{Mapa} faculdade{Faculdade} other{Outros}}",
"@nav_title": {},
"news": "Notícias",
"@news": {},
Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class ApplicationState extends State<Application> {
page: const AcademicPathPageView(),
settings: settings,
),
'/${NavigationItem.navTransports.route}':
'/${NavigationItem.navMap.route}':
PageTransition.makePageTransition(
page: const TransportsPageView(),
settings: settings,
Expand Down
46 changes: 14 additions & 32 deletions packages/uni_app/lib/utils/navbar_items.dart
Original file line number Diff line number Diff line change
@@ -1,52 +1,34 @@
import 'package:flutter/material.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni_ui/icons.dart';

enum NavbarItem {
navPersonalArea(
Icons.home_outlined,
Icons.home,
UniIcons.home,
NavigationItem.navPersonalArea,
),
navAcademicPath(
Icons.school_outlined,
Icons.school,
UniIcons.graduationCap,
NavigationItem.navAcademicPath,
),
navRestaurants(
Icons.free_breakfast_outlined,
Icons.free_breakfast,
UniIcons.restaurant,
NavigationItem.navRestaurants,
),
navFaculty(Icons.domain_outlined, Icons.domain, NavigationItem.navFaculty),
navTransports(Icons.map_outlined, Icons.map, NavigationItem.navTransports);
navFaculty(
UniIcons.faculty,
NavigationItem.navFaculty,
),
navMap(
UniIcons.map,
NavigationItem.navMap,
);

const NavbarItem(this.unselectedIcon, this.selectedIcon, this.item);
const NavbarItem(this.icon, this.item);

final IconData unselectedIcon;
final IconData selectedIcon;
final IconData icon;
final NavigationItem item;

BottomNavigationBarItem toUnselectedBottomNavigationBarItem(
BuildContext context,
) {
return BottomNavigationBarItem(
icon: Icon(unselectedIcon),
label: '',
tooltip: S.of(context).nav_title(item.route),
);
}

BottomNavigationBarItem toSelectedBottomNavigationBarItem(
BuildContext context,
) {
return BottomNavigationBarItem(
icon: Icon(selectedIcon),
label: '',
tooltip: S.of(context).nav_title(item.route),
);
}

String get route {
return item.route;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/lib/utils/navigation_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum NavigationItem {
navAcademicPath('percurso_academico'),
navProfile('perfil'),
navSettings('definicoes'),
navTransports('transportes'),
navMap('mapa'),
navLogin('login'),
navBugreport('bug_report'),
navAboutus('sobre_nos');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,48 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:provider/provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/model/providers/startup/profile_provider.dart';
import 'package:uni/model/providers/startup/session_provider.dart';
import 'package:uni/view/common_widgets/expanded_image_label.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/widgets/bottom_navigation_bar.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/widgets/profile_button.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/widgets/refresh_state.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/widgets/top_navigation_bar.dart';

/// Page with a hamburger menu and the user profile picture
abstract class GeneralPageViewState<T extends StatefulWidget> extends State<T> {
bool _loadedOnce = false;
bool _loading = true;
bool _connected = true;

// Function called when the user pulls down the screen to refresh
Future<void> onRefresh(BuildContext context);

// Function called when the page is loaded
Future<void> onLoad(BuildContext context) async {}

// Right action button on the top navigation bar
Widget? getTopRightButton(BuildContext context) {
return null;
}

// Top navigation bar
AppTopNavbar? getTopNavbar(BuildContext context) {
return AppTopNavbar(
title: this.getTitle(),
rightButton: getTopRightButton(context),
);
}

// This is the widget that will be displayed above the body and below the top navigation bar
Widget? getHeader(BuildContext context) {
return null;
}

// The title of the page
String? getTitle();

// The content of the page
Widget getBody(BuildContext context);

@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
Expand Down Expand Up @@ -55,6 +76,7 @@ abstract class GeneralPageViewState<T extends StatefulWidget> extends State<T> {
}
});

// TODO:(thePeras): Is this stills a thing?
if (!_connected) {
return getScaffold(
context,
Expand Down Expand Up @@ -84,59 +106,22 @@ abstract class GeneralPageViewState<T extends StatefulWidget> extends State<T> {
);
}

Widget? getHeader(BuildContext context) {
return null;
}

String? getTitle();

Widget getBody(BuildContext context);

Future<DecorationImage> buildProfileDecorationImage(
BuildContext context, {
bool forceRetrieval = false,
}) async {
final sessionProvider =
Provider.of<SessionProvider>(context, listen: false);
await sessionProvider.ensureInitialized(context);
final profilePictureFile =
await ProfileProvider.fetchOrGetCachedProfilePicture(
sessionProvider.state!,
forceRetrieval: forceRetrieval,
);
return getProfileDecorationImage(profilePictureFile);
}

/// Returns the current user image.
///
/// If the image is not found / doesn't exist returns a generic placeholder.
DecorationImage getProfileDecorationImage(File? profilePicture) {
const fallbackPicture = AssetImage('assets/images/profile_placeholder.png');
final image =
profilePicture == null ? fallbackPicture : FileImage(profilePicture);

final result =
DecorationImage(fit: BoxFit.cover, image: image as ImageProvider);
return result;
}

Widget getScaffold(BuildContext context, Widget body) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
appBar: getTopNavbar(context),
bottomNavigationBar: const AppBottomNavbar(),
body: RefreshState(
onRefresh: onRefresh,
header: getHeader(context),
body: body,
return MediaQuery.removePadding(
// Prevent misalignment of navbar icons
context: context,
removeBottom: true,
child: Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
appBar: getTopNavbar(context),
extendBody: true, // Allow body to appear behind the bottom navbar
bottomNavigationBar: const AppBottomNavbar(),
body: RefreshState(
onRefresh: onRefresh,
header: getHeader(context),
body: body,
),
),
);
}

AppTopNavbar? getTopNavbar(BuildContext context) {
return AppTopNavbar(
title: this.getTitle(),
rightButton: const ProfileButton(),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:uni/utils/navbar_items.dart';
import 'package:uni_ui/navbar/bottom_navbar.dart';
import 'package:uni_ui/navbar/bottom_navbar_item.dart';

class AppBottomNavbar extends StatelessWidget {
const AppBottomNavbar({super.key});
Expand All @@ -23,53 +25,34 @@ class AppBottomNavbar extends StatelessWidget {
}

void _onItemTapped(BuildContext context, int index) {
final prev = _getCurrentRoute(context);
final item = NavbarItem.values[index];
final key = item.route;
final newRoute = NavbarItem.values[index].route;

if (prev != key) {
if (_getCurrentRoute(context) != newRoute) {
Navigator.pushNamed(
context,
'/$key',
'/$newRoute',
);
}
}

@override
Widget build(BuildContext context) {
final currentIndex = _getCurrentIndex(context);
final navbarItems = <BottomNavigationBarItem>[];
final navbarItems = <BottomNavbarItem>[];
for (var index = 0; index < NavbarItem.values.length; index++) {
final item = NavbarItem.values[index];
navbarItems.insert(
index,
index == currentIndex
? item.toSelectedBottomNavigationBarItem(context)
: item.toUnselectedBottomNavigationBarItem(context),
BottomNavbarItem(
icon: item.icon,
isSelected: () => currentIndex == index,
onTap: () => _onItemTapped(context, index),
),
);
}

return Theme(
data: Theme.of(context).copyWith(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: BottomNavigationBar(
backgroundColor: Theme.of(context).colorScheme.surface,
items: navbarItems,
onTap: (index) => _onItemTapped(context, index),
currentIndex: currentIndex == -1 ? 0 : currentIndex,
type: BottomNavigationBarType.fixed,
iconSize: 32,
selectedItemColor: currentIndex == -1
? Theme.of(context).colorScheme.onSurface
: Theme.of(context).colorScheme.secondary,
unselectedItemColor: Theme.of(context).colorScheme.onSurface,
selectedFontSize: 0,
unselectedFontSize: 0,
showSelectedLabels: false,
showUnselectedLabels: false,
),
return BottomNavbar(
items: navbarItems,
);
}
}
Loading

0 comments on commit 881f3e5

Please sign in to comment.