From 3455eae5dba3db453b97fe7b4a12a6a46c2eb60f Mon Sep 17 00:00:00 2001 From: Yuta1409 Date: Fri, 15 Mar 2024 16:26:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8:=20fetching=20and=20display=20on=20pr?= =?UTF-8?q?ofile=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/profils/views/profil_page.dart | 31 ++++++++++++++++--- frontend/app_student/lib/routes.dart | 19 +++++++++--- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/frontend/app_student/lib/profils/views/profil_page.dart b/frontend/app_student/lib/profils/views/profil_page.dart index f2cb401..09356f4 100644 --- a/frontend/app_student/lib/profils/views/profil_page.dart +++ b/frontend/app_student/lib/profils/views/profil_page.dart @@ -3,14 +3,35 @@ 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'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/svg.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:intl/intl.dart'; + +import '../../users/cubit/user_cubit.dart'; class ProfilPage extends StatelessWidget { const ProfilPage({super.key}); @override Widget build(BuildContext context) { + final userState = context.watch().state; + String firstName = ''; + String className = ''; + 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; + } + + String birthDateString = birthDate != null + ? DateFormat('dd/MM/yyyy').format(birthDate) + : 'error'; + return Scaffold( body: Column( children: [ @@ -18,7 +39,7 @@ class ProfilPage extends StatelessWidget { Padding( padding: const EdgeInsets.all(15.0), child: HeaderText( - AppLocalizations.of(context)!.profilMessageTitle, + '${AppLocalizations.of(context)!.profilMessageTitle} $firstName', ), ), Padding( @@ -37,8 +58,8 @@ class ProfilPage extends StatelessWidget { ), ), ), - title: const Text('Classe'), - subtitle: const Text('Nom du user'), + title: Text(className), + subtitle: Text(firstName), ), ), ), @@ -58,8 +79,8 @@ class ProfilPage extends StatelessWidget { ), ), ), - title: const Text('ISBN'), - subtitle: const Text('dd/mm/yyyy'), + title: Text(ine), + subtitle: Text(birthDateString), ), ), ), diff --git a/frontend/app_student/lib/routes.dart b/frontend/app_student/lib/routes.dart index 3ebedc9..ba9bc93 100644 --- a/frontend/app_student/lib/routes.dart +++ b/frontend/app_student/lib/routes.dart @@ -96,10 +96,19 @@ class AppRoutes { ), ))), GoRoute( - path: profilPage, - pageBuilder: (context, state) => MaterialPage( - key: state.pageKey, - child: const ProfilPage(), - )), + path: profilPage, + pageBuilder: (context, state) => MaterialPage( + key: state.pageKey, + child: RepositoryProvider( + create: (context) => UserRepository(), + child: BlocProvider( + create: (context) => + UserCubit(userRepository: context.read()) + ..fetchUser(), + child: const ProfilPage(), + ), + ), + ), + ), ]; }