-
Notifications
You must be signed in to change notification settings - Fork 6
/
profile.screen.dart
130 lines (123 loc) · 4.96 KB
/
profile.screen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import 'package:fireflutter_sample_app/global_variables.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
class ProfileScreen extends StatefulWidget {
@override
_RegisterScreenState createState() => _RegisterScreenState();
}
class _RegisterScreenState extends State<ProfileScreen> {
TextEditingController displayNameController =
TextEditingController(text: ff.user.displayName);
TextEditingController favoriteColorController =
TextEditingController(text: ff.userData['favoriteColor']);
bool loading = false;
double uploadProgress = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ProfileScreen'),
),
body: ff.notLoggedIn
? Text('Please login')
: Column(
children: [
StreamBuilder(
stream: ff.userChange,
builder: (context, snapshot) {
if (ff.user.photoURL == null) return Container();
return SizedBox(
width: 120,
height: 120,
child: Image.network(ff.user.photoURL));
}),
RaisedButton(
onPressed: () async {
ImageSource source = await showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text('Choose Camera or Gallery'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: () =>
Get.back(result: ImageSource.camera),
child: Text('Camera'),
),
TextButton(
onPressed: () =>
Get.back(result: ImageSource.gallery),
child: Text('Gallery'),
),
],
),
),
);
if (source == null) return null;
try {
if (!ff.user.photoURL.isNullOrBlank) {
await ff.deleteFile(ff.user.photoURL);
}
final url = await ff.uploadFile(
folder: 'user-profile-photos',
source: source,
progress: (p) =>
setState(() => this.uploadProgress = p),
);
await ff.updatePhoto(url);
setState(() => uploadProgress = 0);
} catch (e) {
Get.snackbar('Error', e.toString());
}
},
child: Text('Upload Profile Photo'),
),
if (ff.user.photoURL.isNullOrBlank)
RaisedButton(
onPressed: () async {
if (!ff.user.photoURL.isNullOrBlank) {
await ff.deleteFile(ff.user.photoURL);
await ff.updatePhoto('');
}
},
child: Text('Delete Profile Photo')),
if (uploadProgress != 0) Text('$uploadProgress%'),
Text('My Email: ${ff.user.email}'),
TextFormField(
controller: displayNameController,
decoration: InputDecoration(hintText: 'displayName'),
),
TextFormField(
controller: favoriteColorController,
decoration:
InputDecoration(hintText: 'What is your favorite color?'),
),
RaisedButton(
onPressed: () async {
setState(() => loading = true);
try {
await ff.updateProfile({
'displayName': displayNameController.text,
'favoriteColor': favoriteColorController.text
}, meta: {
"public": {
"notifyPost": true,
"notifyComment": true,
}
});
setState(() => loading = false);
Get.snackbar('Success', 'Profile has been updated!');
} catch (e) {
setState(() => loading = false);
Get.snackbar('Error', e.toString());
}
},
child: loading ? CircularProgressIndicator() : Text('Update'),
),
],
),
);
}
}