1
1
import 'package:auto_route/auto_route.dart' ;
2
2
import 'package:flutter/material.dart' ;
3
3
import 'package:get_it/get_it.dart' ;
4
+ import 'package:pdg_app/model/user.dart' ;
4
5
import 'package:pdg_app/widgets/cards/left_element_card.dart' ;
5
6
import 'package:pdg_app/widgets/profile_template.dart' ;
6
7
import '../router/router.gr.dart' ;
8
+ import '../widgets/buttons/custom_icon_button.dart' ;
7
9
import '../widgets/custom_divider.dart' ;
8
10
9
11
import '../provider/auth_provider.dart' ;
10
12
11
13
class ProfileScreen extends StatelessWidget {
12
14
const ProfileScreen ({Key ? key}) : super (key: key);
13
15
16
+ // IDietitian dietitianApi = FirebaseDietitian(FirebaseFirestore.instance);
17
+
18
+ // Dietitian dietitian = await dietitianApi.readDietitian("bZB6G7LbLSfp8lTPsh00fWxiHb03");
19
+
14
20
@override
15
21
Widget build (BuildContext context) {
22
+ final authProvider = GetIt .I .get <AuthProvider >();
23
+ final User ? user = authProvider.user;
24
+
25
+ if (user == null ) {
26
+ return Center (
27
+ child: Column (
28
+ mainAxisAlignment: MainAxisAlignment .center,
29
+ children: [
30
+ const Text ("An error has occured." ),
31
+ CustomIconButton (
32
+ icon: Icons .logout_outlined,
33
+ onTap: () {
34
+ authProvider.signOut ();
35
+ AutoRouter .of (context).navigate (const LoginScreenRoute ());
36
+ },
37
+ )
38
+ ],
39
+ ),
40
+ );
41
+ }
42
+
16
43
return Profile (
17
- clientFirstName: "Luca" ,
18
- clienLastName: "Coduri" ,
19
- nutriFirstName: "Claire" ,
20
- nutriLastName: "Nutri" ,
21
-
22
- clientPhone: "0794563418" ,
23
- clientBirthday: DateTime (1996 , 12 , 18 ),
24
- clientInsurance: "09734789789248943" ,
44
+ clientFirstName: user.firstName,
45
+ clienLastName: user.lastName,
46
+ blockEnabled: ! authProvider.isAdmin,
47
+ blockText: authProvider.clientDietitian == null
48
+ ? "Yous nutritionnist hasn't contact you yet."
49
+ : "Your nutritionnist is ${authProvider .clientDietitian !.firstName } ${authProvider .clientDietitian !.lastName }." ,
50
+ clientEmail: user.email,
51
+ clientPhone: user.phoneNumber,
52
+ clientBirthday: user.birthDate,
53
+ clientInsurance: user.avs,
25
54
onLogoutPressed: () {
26
55
GetIt .I .get <AuthProvider >().signOut ();
27
56
context.router.replaceAll ([
@@ -37,8 +66,8 @@ class Profile extends StatelessWidget {
37
66
final String _clientPicturePath;
38
67
final String _clientFirstName;
39
68
final String _clientLastName;
40
- final String _nutriFirstName ;
41
- final String _nutriLastName ;
69
+ final bool _blockEnabled ;
70
+ final String _blocText ;
42
71
final String _clientEmail;
43
72
final String _clientPhone;
44
73
final DateTime _clientBirthday;
@@ -50,20 +79,20 @@ class Profile extends StatelessWidget {
50
79
clientPicturePath = 'assets/images/default_user_pic.png' ,
51
80
required clientFirstName,
52
81
required clienLastName,
53
- required nutriFirstName,
54
- required nutriLastName,
55
82
required clientEmail,
56
83
required clientPhone,
57
84
required clientBirthday,
58
85
required clientInsurance,
86
+ blockEnabled = false ,
87
+ blockText = "" ,
59
88
void Function ()? onLogoutPressed,
60
89
Key ? key,
61
90
}) : _screenWidth = screenWidth,
62
91
_clientPicturePath = clientPicturePath,
63
92
_clientFirstName = clientFirstName,
64
93
_clientLastName = clienLastName,
65
- _nutriFirstName = nutriFirstName ,
66
- _nutriLastName = nutriLastName ,
94
+ _blocText = blockText ,
95
+ _blockEnabled = blockEnabled ,
67
96
_clientEmail = clientEmail,
68
97
_clientPhone = clientPhone,
69
98
_clientBirthday = clientBirthday,
@@ -85,18 +114,24 @@ class Profile extends StatelessWidget {
85
114
onIconButtonPressed: _onLogoutPressed,
86
115
buttonIcon: Icons .logout_outlined,
87
116
firstBloc: Column (children: [
88
- LeftElementCard (
89
- title:
90
- Text ("Your nutritionnist is $_nutriFirstName $_nutriLastName ." ),
91
- element: IconTheme (
92
- data: IconThemeData (
93
- color: Theme .of (context).colorScheme.primary,
94
- size: 30 ,
95
- ),
96
- child: const Icon (Icons .notification_important_outlined),
97
- ),
98
- ),
99
- const CustomDivider (),
117
+ _blockEnabled
118
+ ? Column (
119
+ children: [
120
+ LeftElementCard (
121
+ title: Text (_blocText),
122
+ element: IconTheme (
123
+ data: IconThemeData (
124
+ color: Theme .of (context).colorScheme.primary,
125
+ size: 30 ,
126
+ ),
127
+ child:
128
+ const Icon (Icons .notification_important_outlined),
129
+ ),
130
+ ),
131
+ const CustomDivider (),
132
+ ],
133
+ )
134
+ : const SizedBox (),
100
135
const Text ("Personal data" ,
101
136
textAlign: TextAlign .center,
102
137
style: TextStyle (fontWeight: FontWeight .w600, fontSize: 18 )),
0 commit comments