Skip to content

Commit

Permalink
♻️: remove usercard useless at this time, clear class after click on …
Browse files Browse the repository at this point in the history
…button
  • Loading branch information
julesartd committed Apr 10, 2024
1 parent 1e1d44f commit b75f151
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ class UserRepository {
await prefs.remove('birthDate');
await prefs.remove('className');
}

Future<void> clearClass() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.remove('className');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ClassGroupCubit extends Cubit<ClassGroupState> {
try {
emit(ClassGroupLoading());
final classes = await classRepository.getClasses();

emit(ClassGroupLoaded(classes));
} catch (e) {
emit(ClassGroupError(e.toString()));
Expand Down
2 changes: 1 addition & 1 deletion frontend/app_student/lib/menu/menu_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MenuBarViewState extends State<MenuBarView> {

switch (index) {
case 0:
context.read<UserCubit>().deleteUserClass();
context.read<UserCubit>().deleteUser();
GoRouter.of(context).go(AppRoutes.loginPage);
WidgetsBinding.instance.addPostFrameCallback((_) {
Fluttertoast.showToast(
Expand Down
18 changes: 8 additions & 10 deletions frontend/app_student/lib/profils/views/profil.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:app_student/menu/menu_view.dart';
import 'package:app_student/profils/views/widgets/class_group_button.dart';
import 'package:app_student/profils/views/widgets/user_class_card.dart';
import 'package:app_student/profils/views/widgets/user_info_card.dart';
import 'package:app_student/utils/custom_layout.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intl/intl.dart';

import '../../shared_components/header_logo.dart';
import '../../shared_components/header_title.dart';
Expand All @@ -21,19 +19,19 @@ class ProfilPage extends StatelessWidget {
final userState = context.watch<UserCubit>().state;
String firstName = '';
String className = '';
String ine = '';
DateTime? birthDate;
// String ine = '';
// DateTime? birthDate;

if (userState is UserLoaded) {
firstName = userState.user.entity.firstName;
className = userState.user.entity.className!;
ine = userState.user.entity.ine;
birthDate = userState.user.entity.birthDate;
// ine = userState.user.entity.ine;
// birthDate = userState.user.entity.birthDate;
}

String birthDateString = birthDate != null
? DateFormat('dd/MM/yyyy').format(birthDate)
: 'error';
// String birthDateString = birthDate != null
// ? DateFormat('dd/MM/yyyy').format(birthDate)
// : 'error';

return CustomLayout(
appBar: HeaderLogo(appBarHeight: Global.screenHeight * 0.3),
Expand All @@ -46,7 +44,7 @@ class ProfilPage extends StatelessWidget {
),
),
UserClassCard(className: className, firstName: firstName),
UserInfoCard(ine: ine, birthDate: birthDateString),
// UserInfoCard(ine: ine, birthDate: birthDateString),
],
),
bottomContent: const ClassGroupButton(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:app_student/routes.dart';
import 'package:app_student/users/cubit/user_cubit.dart';
import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';

Expand Down Expand Up @@ -30,6 +32,7 @@ class ClassGroupButton extends StatelessWidget {
),
),
onPressed: () {
context.read<UserCubit>().clearUserClass();
GoRouter.of(context).go(AppRoutes.classListPage);
},
child: Text(AppLocalizations.of(context)!.profilChangeClassButton,
Expand Down
6 changes: 5 additions & 1 deletion frontend/app_student/lib/users/cubit/user_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class UserCubit extends Cubit<UserState> {
emit(UserClassesSelected());
}

Future<void> deleteUserClass() async {
Future<void> deleteUser() async {
await userRepository.delete();
}

Future<void> clearUserClass() async {
await userRepository.clearClass();
}
}
2 changes: 1 addition & 1 deletion frontend/app_student/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+9
version: 1.0.0+11

environment:
sdk: '>=3.3.0 <4.0.0'
Expand Down

0 comments on commit b75f151

Please sign in to comment.