Skip to content

Commit

Permalink
feat: add titles to general pages (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes authored Feb 23, 2024
2 parents e1f7d97 + 94bcf02 commit f4d4280
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 43 deletions.
6 changes: 6 additions & 0 deletions uni/lib/view/academic_path/academic_path.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni/view/academic_path/widgets/course_units_card.dart';
import 'package:uni/view/common_widgets/generic_card.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
Expand All @@ -20,6 +22,10 @@ class AcademicPathPageViewState extends GeneralPageViewState {
// Add more cards if needed
];

@override
String? getTitle() =>
S.of(context).nav_title(NavigationItem.navAcademicPath.route);

@override
Widget getBody(BuildContext context) {
return ListView(
Expand Down
2 changes: 1 addition & 1 deletion uni/lib/view/common_widgets/page_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PageTitle extends StatelessWidget {
);
return Container(
padding: pad ? const EdgeInsets.fromLTRB(20, 30, 20, 10) : null,
alignment: center ? Alignment.center : null,
alignment: center ? Alignment.center : Alignment.centerLeft,
child: title,
);
}
Expand Down
12 changes: 10 additions & 2 deletions uni/lib/view/common_widgets/pages_layouts/general/general.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:sentry_flutter/sentry_flutter.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/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';

Expand Down Expand Up @@ -62,6 +63,8 @@ abstract class GeneralPageViewState<T extends StatefulWidget> extends State<T> {
);
}

String? getTitle();

Widget getBody(BuildContext context);

Future<DecorationImage> buildProfileDecorationImage(
Expand Down Expand Up @@ -114,13 +117,18 @@ abstract class GeneralPageViewState<T extends StatefulWidget> extends State<T> {

Widget getScaffold(BuildContext context, Widget body) {
return Scaffold(
appBar: getTopNavbar(context),
bottomNavigationBar: const AppBottomNavbar(),
appBar: getTopNavbar(context),
body: RefreshState(onRefresh: onRefresh, child: body),
);
}

AppTopNavbar? getTopNavbar(BuildContext context) {
return null;
return AppTopNavbar(
title: this.getTitle(),
rightButton: ProfileButton(
getProfileDecorationImage: getProfileDecorationImage,
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ class AppTopNavbar extends StatelessWidget implements PreferredSizeWidget {
final Widget? rightButton;
final Widget? leftButton;

Widget _createTopWidgets(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(leftButton == null ? 20 : 12, 0, 8, 8),
child: Row(
children: [
if (leftButton != null)
Padding(
padding: const EdgeInsets.only(right: 8),
child: leftButton,
),
Expanded(
child: PageTitle(
name: title ?? '',
pad: false,
center: false,
),
),
if (rightButton != null)
Padding(
padding: const EdgeInsets.only(left: 8),
child: rightButton,
),
],
),
);
}

@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);

Expand All @@ -24,27 +51,11 @@ class AppTopNavbar extends StatelessWidget implements PreferredSizeWidget {
automaticallyImplyLeading: false,
elevation: 0,
iconTheme: Theme.of(context).iconTheme,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
backgroundColor: Theme.of(context).colorScheme.background,
shadowColor: Theme.of(context).dividerColor,
surfaceTintColor: Theme.of(context).colorScheme.onSecondary,
titleSpacing: 0,
title: Stack(
alignment: Alignment.center,
children: [
Align(
alignment: Alignment.centerLeft,
child: leftButton,
),
Center(
child: PageTitle(
name: title ?? '',
pad: false,
),
),
Align(
alignment: Alignment.centerRight,
child: rightButton,
),
],
),
title: _createTopWidgets(context),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ abstract class SecondaryPageViewState<T extends StatefulWidget>
);
}

@override
String? getTitle();

Widget? getTopRightButton(BuildContext context) {
Expand All @@ -28,10 +29,7 @@ abstract class SecondaryPageViewState<T extends StatefulWidget>
AppTopNavbar? getTopNavbar(BuildContext context) {
return AppTopNavbar(
title: getTitle(),
leftButton: const Padding(
padding: EdgeInsets.symmetric(horizontal: 8),
child: BackButton(),
),
leftButton: const BackButton(),
rightButton: getTopRightButton(context),
);
}
Expand Down
6 changes: 6 additions & 0 deletions uni/lib/view/faculty/faculty.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/model/providers/lazy/library_occupation_provider.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni/view/calendar/widgets/calendar_card.dart';
import 'package:uni/view/common_widgets/generic_expansion_card.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
Expand All @@ -21,6 +23,10 @@ class FacultyPageView extends StatefulWidget {
}

class FacultyPageViewState extends GeneralPageViewState {
@override
String? getTitle() =>
S.of(context).nav_title(NavigationItem.navFaculty.route);

@override
Widget getBody(BuildContext context) {
return ListView(
Expand Down
10 changes: 5 additions & 5 deletions uni/lib/view/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ class HomePageViewState extends GeneralPageViewState {
}
}

@override
String? getTitle() => null;

@override
AppTopNavbar? getTopNavbar(BuildContext context) {
return AppTopNavbar(
leftButton: const Padding(
padding: EdgeInsets.symmetric(horizontal: 8),
child: UniIcon(),
),
rightButton: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: ProfileButton(
getProfileDecorationImage: getProfileDecorationImage,
),
rightButton: ProfileButton(
getProfileDecorationImage: getProfileDecorationImage,
),
);
}
Expand Down
3 changes: 2 additions & 1 deletion uni/lib/view/home/widgets/main_cards_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MainCardsListState extends State<MainCardsList> {
),
)
: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
createTopBar(context),
...favoriteCardsFromTypes(
Expand Down Expand Up @@ -147,7 +148,7 @@ class MainCardsListState extends State<MainCardsList> {
BuildContext context,
) {
return Container(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expand Down
15 changes: 6 additions & 9 deletions uni/lib/view/home/widgets/uni_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ class UniIcon extends StatelessWidget {
return ButtonTheme(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: const RoundedRectangleBorder(),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: SvgPicture.asset(
colorFilter: ColorFilter.mode(
Theme.of(context).primaryColor,
BlendMode.srcIn,
),
'assets/images/logo_dark.svg',
height: 35,
child: SvgPicture.asset(
colorFilter: ColorFilter.mode(
Theme.of(context).primaryColor,
BlendMode.srcIn,
),
'assets/images/logo_dark.svg',
height: 35,
),
);
}
Expand Down
6 changes: 5 additions & 1 deletion uni/lib/view/restaurant/restaurant_page_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:uni/model/entities/meal.dart';
import 'package:uni/model/entities/restaurant.dart';
import 'package:uni/model/providers/lazy/restaurant_provider.dart';
import 'package:uni/model/utils/day_of_week.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/view/lazy_consumer.dart';
import 'package:uni/view/locale_notifier.dart';
Expand Down Expand Up @@ -34,6 +35,10 @@ class _RestaurantPageViewState extends GeneralPageViewState<RestaurantPageView>
scrollViewController = ScrollController();
}

@override
String? getTitle() =>
S.of(context).nav_title(NavigationItem.navRestaurants.route);

@override
Widget getBody(BuildContext context) {
return Column(
Expand All @@ -42,7 +47,6 @@ class _RestaurantPageViewState extends GeneralPageViewState<RestaurantPageView>
controller: tabController,
isScrollable: true,
tabs: createTabs(context),
padding: const EdgeInsets.only(top: 40),
),
LazyConsumer<RestaurantProvider, List<Restaurant>>(
builder: (context, restaurants) => createTabViewBuilder(
Expand Down
6 changes: 6 additions & 0 deletions uni/lib/view/transports/transports.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni/view/common_widgets/generic_card.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/view/home/widgets/bus_stop_card.dart';
Expand All @@ -18,6 +20,10 @@ class TransportsPageViewState extends GeneralPageViewState {
// Add more cards if needed
];

@override
String? getTitle() =>
S.of(context).nav_title(NavigationItem.navTransports.route);

@override
Widget getBody(BuildContext context) {
return ListView(
Expand Down

0 comments on commit f4d4280

Please sign in to comment.