Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI/configuration menu #43

Merged
merged 14 commits into from
Mar 15, 2024
2 changes: 1 addition & 1 deletion frontend/app_student/.run/main_prod.run.xml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yan stop opening your fucking whole project in Android Studio thanks

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="main_prod" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/lib/main_prod.dart" />
<option name="filePath" value="$PROJECT_DIR$/frontend/app_student/lib/main_prod.dart" />
<method v="2" />
</configuration>
</component>
106 changes: 68 additions & 38 deletions frontend/app_student/lib/menu/menu_view.dart
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cool to make another file just for the icon, passing the icon as an argument. This would reduce the number of lines, and if you want to change the design, you can only change it in 1 place and not on the 3 buttons.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:app_student/routes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';

class MenuBarView extends StatefulWidget {
const MenuBarView({super.key});
Expand All @@ -9,56 +11,84 @@ class MenuBarView extends StatefulWidget {
}

class MenuBarViewState extends State<MenuBarView> {
int _selectedIndex = 0;
int _selectedIndex = 1;

@override
void initState() {
super.initState();
_setSelectedIndex();
}

void _setSelectedIndex() {
final route = GoRouter.of(context).routeInformationProvider.value.uri.path;

if (route == AppRoutes.loginPage) {
_selectedIndex = 0;
} else if (route == AppRoutes.schedulePage) {
_selectedIndex = 1;
} else if (route == AppRoutes.profilPage) {
_selectedIndex = 2;
}
}

void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});

switch (index) {
case 0:
GoRouter.of(context).go(AppRoutes.loginPage);
break;
case 1:
GoRouter.of(context).go(AppRoutes.schedulePage);
break;
case 2:
GoRouter.of(context).go(AppRoutes.profilPage);
break;
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: SvgPicture.asset(
'assets/images/disconnect.svg',
height: 20,
width: 20,
colorFilter: _selectedIndex == 0
? const ColorFilter.mode(Colors.blue, BlendMode.srcIn)
: null,
),
label: '',
return BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: SvgPicture.asset(
'assets/images/disconnect.svg',
height: 20,
width: 20,
colorFilter: _selectedIndex == 0
? const ColorFilter.mode(Colors.blue, BlendMode.srcIn)
: null,
),
BottomNavigationBarItem(
icon: SvgPicture.asset(
'assets/images/calendar.svg',
height: 20,
width: 20,
colorFilter: _selectedIndex == 1
? const ColorFilter.mode(Colors.blue, BlendMode.srcIn)
: null,
),
label: '',
label: '',
),
BottomNavigationBarItem(
icon: SvgPicture.asset(
'assets/images/calendar.svg',
height: 20,
width: 20,
colorFilter: _selectedIndex == 1
? const ColorFilter.mode(Colors.blue, BlendMode.srcIn)
: null,
),
BottomNavigationBarItem(
icon: SvgPicture.asset(
'assets/images/profil.svg',
height: 20,
width: 20,
colorFilter: _selectedIndex == 2
? const ColorFilter.mode(Colors.blue, BlendMode.srcIn)
: null,
),
label: '',
label: '',
),
BottomNavigationBarItem(
icon: SvgPicture.asset(
'assets/images/profil.svg',
height: 20,
width: 20,
colorFilter: _selectedIndex == 2
? const ColorFilter.mode(Colors.blue, BlendMode.srcIn)
: null,
),
],
currentIndex: _selectedIndex,
onTap: _onItemTapped,
),
label: '',
),
],
currentIndex: _selectedIndex,
onTap: _onItemTapped,
);
}
}
2 changes: 2 additions & 0 deletions frontend/app_student/lib/profils/views/profil_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:app_student/class_groups/views/widgets/header/header_text.dart';
import 'package:app_student/menu/menu_view.dart';
import 'package:app_student/profils/views/widgets/class_group_button.dart';
import 'package:flutter/material.dart';
import 'package:app_student/login/widgets/header/header_logo.dart';
Expand Down Expand Up @@ -62,6 +63,7 @@ class ProfilPage extends StatelessWidget {
const ClassGroupButton(),
],
),
bottomNavigationBar: const MenuBarView(),
);
}
}
8 changes: 8 additions & 0 deletions frontend/app_student/lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:app_student/api/users/repositories/user_repository.dart';
import 'package:app_student/api/week_schedule/repositories/week_schedule_repository.dart';
import 'package:app_student/class_groups/cubit/class_group_cubit.dart';
import 'package:app_student/config/config.dart';
import 'package:app_student/profils/views/profil_page.dart';
import 'package:app_student/users/cubit/user_cubit.dart';
import 'package:app_student/week_schedule/cubit/week_schedule_cubit.dart';
import 'package:app_student/week_schedule/views/week_schedule.dart';
Expand All @@ -20,6 +21,7 @@ class AppRoutes {
static const classListPage = '/classList';
static const loginPage = '/login';
static const schedulePage = '/schedule';
static const profilPage = '/profil';

static final routes = [
GoRoute(
Expand Down Expand Up @@ -93,5 +95,11 @@ class AppRoutes {
child: const WeekSchedulePage(),
),
))),
GoRoute(
path: profilPage,
pageBuilder: (context, state) => MaterialPage<void>(
key: state.pageKey,
child: const ProfilPage(),
)),
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class WeekScheduleCubit extends Cubit<WeekScheduleState> {

Future fetchWeekSchedule() async {
try {
if (isClosed) return;
if (isClosed) {
return;
}
emit(WeekScheduleLoading());
final user = await userCubit.getCurrentUser();
final weekSchedule =
Expand All @@ -38,8 +40,14 @@ class WeekScheduleCubit extends Cubit<WeekScheduleState> {
daySchedule.date.month == initialDate!.month &&
daySchedule.date.year == initialDate!.year);

if (isClosed) {
return;
}
emit(WeekScheduleLoaded(weekSchedule, todayIndex, allEvents, user));
} catch (e) {
if (isClosed) {
return;
}
emit(WeekScheduleError(e.toString()));
}
}
Expand Down
77 changes: 40 additions & 37 deletions frontend/app_student/lib/week_schedule/views/week_schedule.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:app_student/api/week_schedule/repositories/week_schedule_repository.dart';
import 'package:app_student/menu/menu_view.dart';
import 'package:app_student/users/cubit/user_cubit.dart';
import 'package:app_student/week_schedule/cubit/week_schedule_cubit.dart';
import 'package:app_student/week_schedule/views/widgets/day_schedule_widget.dart';
Expand All @@ -24,46 +25,48 @@ class WeekSchedulePage extends StatelessWidget {
initialDate: initialDate);

return BlocProvider<WeekScheduleCubit>(
create: (context) => weekScheduleCubit..fetchUserAndSchedule(),
child: BlocProvider<UserCubit>(
create: (context) =>
UserCubit(userRepository: userRepository)..fetchUser(),
child: Scaffold(
appBar: const AppBarWeekSchedule(),
body: BlocBuilder<WeekScheduleCubit, WeekScheduleState>(
builder: (context, state) {
if (state is WeekScheduleLoading) {
return const Center(child: CircularProgressIndicator());
} else if (state is WeekScheduleLoaded) {
final allEvents = state.weekSchedule
.expand((week) => week.daySchedules)
.toList();
create: (context) => weekScheduleCubit..fetchUserAndSchedule(),
child: BlocProvider<UserCubit>(
create: (context) =>
UserCubit(userRepository: userRepository)..fetchUser(),
child: Scaffold(
appBar: const AppBarWeekSchedule(),
body: BlocBuilder<WeekScheduleCubit, WeekScheduleState>(
builder: (context, state) {
if (state is WeekScheduleLoading) {
return const Center(child: CircularProgressIndicator());
} else if (state is WeekScheduleLoaded) {
final allEvents = state.weekSchedule
.expand((week) => week.daySchedules)
.toList();

return Padding(
padding: const EdgeInsets.only(top: 30.0),
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: PageView.builder(
controller: PageController(
initialPage:
state.todayIndex != -1 ? state.todayIndex : 0,
),
itemCount: allEvents.length,
itemBuilder: (context, index) {
final daySchedule = allEvents[index];
return DayScheduleWidget(daySchedule: daySchedule);
},
return Padding(
padding: const EdgeInsets.only(top: 30.0),
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: PageView.builder(
controller: PageController(
initialPage:
state.todayIndex != -1 ? state.todayIndex : 0,
),
itemCount: allEvents.length,
itemBuilder: (context, index) {
final daySchedule = allEvents[index];
return DayScheduleWidget(daySchedule: daySchedule);
},
),
);
} else if (state is WeekScheduleError) {
return Center(child: Text(state.message));
} else {
return const SizedBox.shrink();
}
},
),
),
);
} else if (state is WeekScheduleError) {
return Center(child: Text(state.message));
} else {
return const SizedBox.shrink();
}
},
),
));
bottomNavigationBar: const MenuBarView(),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'package:app_student/users/cubit/user_cubit.dart';
import 'package:app_student/week_schedule/views/widgets/components/datepicker_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'datepicker_button.dart';

class AppBarWeekSchedule extends StatelessWidget
implements PreferredSizeWidget {
const AppBarWeekSchedule({super.key});

static const double appBarHeight = 80.0;

@override
Widget build(BuildContext context) {
final userState = context.watch<UserCubit>().state;
Expand All @@ -16,7 +19,7 @@ class AppBarWeekSchedule extends StatelessWidget
}
return AppBar(
backgroundColor: const Color(0xFF005067),
title: const SizedBox.shrink(), // Make the title empty
title: const SizedBox.shrink(),
flexibleSpace: Stack(
alignment: Alignment.center,
children: [
Expand All @@ -25,7 +28,7 @@ class AppBarWeekSchedule extends StatelessWidget
child: Opacity(
opacity: 0.5,
child: Transform.scale(
scale: 3.0, // Adjust the scale factor to zoom the image
scale: 3.0,
child: Image.asset(
'assets/images/3il-icon-white.png',
fit: BoxFit.cover,
Expand All @@ -52,5 +55,5 @@ class AppBarWeekSchedule extends StatelessWidget
}

@override
Size get preferredSize => const Size.fromHeight(70.0);
Size get preferredSize => const Size.fromHeight(appBarHeight);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EventDetails extends StatelessWidget {
EventHours(event: event),
SizedBox(
width:
constraints.maxWidth - 50, // Subtract the width of EventHours
constraints.maxWidth - 80, // Subtract the width of EventHours
child: EventInfo(event: event),
),
],
Expand Down
Loading