@@ -23,14 +23,26 @@ import 'package:wger/models/user/profile.dart';
23
23
import 'package:wger/providers/user.dart' ;
24
24
import 'package:wger/theme/theme.dart' ;
25
25
26
- class UserProfileForm extends StatelessWidget {
26
+ class UserProfileForm extends StatefulWidget {
27
27
late final Profile _profile;
28
- final _form = GlobalKey <FormState >();
29
- final emailController = TextEditingController ();
30
28
31
29
UserProfileForm (Profile profile) {
32
30
_profile = profile;
33
- emailController.text = _profile.email;
31
+ }
32
+
33
+ @override
34
+ State <UserProfileForm > createState () => _UserProfileFormState ();
35
+ }
36
+
37
+ class _UserProfileFormState extends State <UserProfileForm > {
38
+ final _form = GlobalKey <FormState >();
39
+
40
+ final emailController = TextEditingController ();
41
+
42
+ @override
43
+ void initState () {
44
+ super .initState ();
45
+ emailController.text = widget._profile.email;
34
46
}
35
47
36
48
@override
@@ -42,16 +54,29 @@ class UserProfileForm extends StatelessWidget {
42
54
ListTile (
43
55
leading: const Icon (Icons .person, color: wgerPrimaryColor),
44
56
title: Text (AppLocalizations .of (context).username),
45
- subtitle: Text (_profile.username),
57
+ subtitle: Text (widget._profile.username),
58
+ ),
59
+ SwitchListTile (
60
+ title: Text (AppLocalizations .of (context).useMetric),
61
+ subtitle: Text (widget._profile.weightUnitStr),
62
+ value: widget._profile.isMetric,
63
+ onChanged: (_) {
64
+ setState (() {
65
+ widget._profile.weightUnitStr = widget._profile.isMetric
66
+ ? AppLocalizations .of (context).lb
67
+ : AppLocalizations .of (context).kg;
68
+ });
69
+ },
70
+ dense: true ,
46
71
),
47
72
ListTile (
48
73
leading: const Icon (Icons .email_rounded, color: wgerPrimaryColor),
49
74
title: TextFormField (
50
75
decoration: InputDecoration (
51
- labelText: _profile.emailVerified
76
+ labelText: widget. _profile.emailVerified
52
77
? AppLocalizations .of (context).verifiedEmail
53
78
: AppLocalizations .of (context).unVerifiedEmail,
54
- suffixIcon: _profile.emailVerified
79
+ suffixIcon: widget. _profile.emailVerified
55
80
? const Icon (
56
81
Icons .check_circle,
57
82
color: Colors .green,
@@ -60,7 +85,7 @@ class UserProfileForm extends StatelessWidget {
60
85
controller: emailController,
61
86
keyboardType: TextInputType .emailAddress,
62
87
onSaved: (newValue) {
63
- _profile.email = newValue! ;
88
+ widget. _profile.email = newValue! ;
64
89
},
65
90
validator: (value) {
66
91
if (value! .isNotEmpty && ! value.contains ('@' )) {
@@ -70,11 +95,11 @@ class UserProfileForm extends StatelessWidget {
70
95
},
71
96
),
72
97
),
73
- if (! _profile.emailVerified)
98
+ if (! widget. _profile.emailVerified)
74
99
OutlinedButton (
75
100
onPressed: () async {
76
101
// Email is already verified
77
- if (_profile.emailVerified) {
102
+ if (widget. _profile.emailVerified) {
78
103
return ;
79
104
}
80
105
@@ -83,17 +108,14 @@ class UserProfileForm extends StatelessWidget {
83
108
ScaffoldMessenger .of (context).showSnackBar (
84
109
SnackBar (
85
110
content: Text (
86
- AppLocalizations .of (context).verifiedEmailInfo (_profile.email),
111
+ AppLocalizations .of (context).verifiedEmailInfo (widget. _profile.email),
87
112
),
88
113
),
89
114
);
90
115
},
91
116
child: Text (AppLocalizations .of (context).verify),
92
117
),
93
118
ElevatedButton (
94
- style: ElevatedButton .styleFrom (
95
- backgroundColor: wgerPrimaryButtonColor,
96
- shape: RoundedRectangleBorder (borderRadius: BorderRadius .circular (50 ))),
97
119
onPressed: () async {
98
120
// Validate and save the current values to the weightEntry
99
121
final isValid = _form.currentState! .validate ();
0 commit comments