Skip to content

Commit 02da2b9

Browse files
committed
fix(profile_edit): fix page
1 parent 174d5ea commit 02da2b9

6 files changed

Lines changed: 75 additions & 179 deletions

File tree

lib/l10n/app_en.arb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158

159159
"profileEditTitle": "Edit Profile",
160160
"profileEditAvatar": "Avatar",
161-
"profileEditBackground": "Background",
162161
"profileEditBasicInfo": "Basic Information",
163162
"profileEditUsername": "Username",
164163
"profileEditEmail": "Email",
@@ -168,9 +167,7 @@
168167
"profileEditIntroductionPlaceholder": "Write something about yourself...",
169168
"profileEditSaveChanges": "Save Changes",
170169
"profileEditChangeAvatar": "Change Avatar",
171-
"profileEditChangeBackground": "Change Background",
172170
"profileEditRemoveAvatar": "Remove Avatar",
173-
"profileEditRemoveBackground": "Remove Background",
174171
"profileEditUpdated": "Profile updated",
175172
"profileEditUsernameCannotChange": "Username cannot be changed",
176173

lib/l10n/app_localizations.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -872,12 +872,6 @@ abstract class AppLocalizations {
872872
/// **'Avatar'**
873873
String get profileEditAvatar;
874874

875-
/// No description provided for @profileEditBackground.
876-
///
877-
/// In en, this message translates to:
878-
/// **'Background'**
879-
String get profileEditBackground;
880-
881875
/// No description provided for @profileEditBasicInfo.
882876
///
883877
/// In en, this message translates to:
@@ -932,24 +926,12 @@ abstract class AppLocalizations {
932926
/// **'Change Avatar'**
933927
String get profileEditChangeAvatar;
934928

935-
/// No description provided for @profileEditChangeBackground.
936-
///
937-
/// In en, this message translates to:
938-
/// **'Change Background'**
939-
String get profileEditChangeBackground;
940-
941929
/// No description provided for @profileEditRemoveAvatar.
942930
///
943931
/// In en, this message translates to:
944932
/// **'Remove Avatar'**
945933
String get profileEditRemoveAvatar;
946934

947-
/// No description provided for @profileEditRemoveBackground.
948-
///
949-
/// In en, this message translates to:
950-
/// **'Remove Background'**
951-
String get profileEditRemoveBackground;
952-
953935
/// No description provided for @profileEditUpdated.
954936
///
955937
/// In en, this message translates to:

lib/l10n/app_localizations_en.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,6 @@ class AppLocalizationsEn extends AppLocalizations {
409409
@override
410410
String get profileEditAvatar => 'Avatar';
411411

412-
@override
413-
String get profileEditBackground => 'Background';
414-
415412
@override
416413
String get profileEditBasicInfo => 'Basic Information';
417414

@@ -440,15 +437,9 @@ class AppLocalizationsEn extends AppLocalizations {
440437
@override
441438
String get profileEditChangeAvatar => 'Change Avatar';
442439

443-
@override
444-
String get profileEditChangeBackground => 'Change Background';
445-
446440
@override
447441
String get profileEditRemoveAvatar => 'Remove Avatar';
448442

449-
@override
450-
String get profileEditRemoveBackground => 'Remove Background';
451-
452443
@override
453444
String get profileEditUpdated => 'Profile updated';
454445

lib/l10n/app_localizations_zh.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,6 @@ class AppLocalizationsZh extends AppLocalizations {
396396
@override
397397
String get profileEditAvatar => '头像';
398398

399-
@override
400-
String get profileEditBackground => '背景图';
401-
402399
@override
403400
String get profileEditBasicInfo => '基本信息';
404401

@@ -426,15 +423,9 @@ class AppLocalizationsZh extends AppLocalizations {
426423
@override
427424
String get profileEditChangeAvatar => '更改头像';
428425

429-
@override
430-
String get profileEditChangeBackground => '更改背景';
431-
432426
@override
433427
String get profileEditRemoveAvatar => '移除头像';
434428

435-
@override
436-
String get profileEditRemoveBackground => '移除背景';
437-
438429
@override
439430
String get profileEditUpdated => '资料已更新';
440431

lib/l10n/app_zh.arb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@
149149

150150
"profileEditTitle": "编辑资料",
151151
"profileEditAvatar": "头像",
152-
"profileEditBackground": "背景图",
153152
"profileEditBasicInfo": "基本信息",
154153
"profileEditUsername": "用户名",
155154
"profileEditEmail": "邮箱",
@@ -159,9 +158,7 @@
159158
"profileEditIntroductionPlaceholder": "写一段关于你自己的介绍...",
160159
"profileEditSaveChanges": "保存更改",
161160
"profileEditChangeAvatar": "更改头像",
162-
"profileEditChangeBackground": "更改背景",
163161
"profileEditRemoveAvatar": "移除头像",
164-
"profileEditRemoveBackground": "移除背景",
165162
"profileEditUpdated": "资料已更新",
166163
"profileEditUsernameCannotChange": "用户名不可更改",
167164

lib/screens/profile_edit_screen.dart

Lines changed: 75 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import 'dart:io';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter/foundation.dart' show kIsWeb;
34
import 'package:go_router/go_router.dart';
4-
import 'package:image_picker/image_picker.dart';
5+
import 'package:file_picker/file_picker.dart';
56
import 'package:material_symbols_icons/symbols.dart';
67
import '../l10n/app_localizations.dart';
78
import '../models/user_profile.dart';
@@ -18,10 +19,8 @@ class _ProfileEditScreenState extends State<ProfileEditScreen> {
1819
UserProfile? _currentUser;
1920
bool _isSubmitting = false;
2021

21-
// Image pickers
22-
final ImagePicker _imagePicker = ImagePicker();
23-
XFile? _selectedAvatar;
24-
XFile? _selectedBackground;
22+
// File picker
23+
PlatformFile? _selectedAvatar;
2524

2625
// Form fields
2726
late TextEditingController _emailController;
@@ -81,17 +80,30 @@ class _ProfileEditScreenState extends State<ProfileEditScreen> {
8180
);
8281

8382
if (choice == 'change') {
84-
final XFile? image = await _imagePicker.pickImage(
85-
source: ImageSource.gallery,
86-
maxWidth: 512,
87-
maxHeight: 512,
88-
imageQuality: 85,
89-
);
83+
FilePickerResult? result;
84+
85+
if (!kIsWeb && Platform.isAndroid) {
86+
result = await FilePicker.platform.pickFiles(
87+
type: FileType.custom,
88+
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'heic', 'heif'],
89+
allowMultiple: false,
90+
withData: false,
91+
);
92+
} else {
93+
result = await FilePicker.platform.pickFiles(
94+
type: FileType.image,
95+
allowMultiple: false,
96+
withData: true,
97+
);
98+
}
9099

91-
if (image != null) {
92-
setState(() {
93-
_selectedAvatar = image;
94-
});
100+
if (result != null) {
101+
final file = result.files.single;
102+
if (file.bytes != null || file.path != null) {
103+
setState(() {
104+
_selectedAvatar = file;
105+
});
106+
}
95107
}
96108
} else if (choice == 'remove') {
97109
setState(() {
@@ -100,27 +112,6 @@ class _ProfileEditScreenState extends State<ProfileEditScreen> {
100112
}
101113
}
102114

103-
Future<void> _selectBackground() async {
104-
final XFile? image = await _imagePicker.pickImage(
105-
source: ImageSource.gallery,
106-
maxWidth: 1920,
107-
maxHeight: 1080,
108-
imageQuality: 85,
109-
);
110-
111-
if (image != null) {
112-
setState(() {
113-
_selectedBackground = image;
114-
});
115-
}
116-
}
117-
118-
void _removeBackground() {
119-
setState(() {
120-
_selectedBackground = null;
121-
});
122-
}
123-
124115
Future<void> _saveProfile() async {
125116
final l10n = AppLocalizations.of(context)!;
126117

@@ -140,7 +131,7 @@ class _ProfileEditScreenState extends State<ProfileEditScreen> {
140131
createTime: _currentUser!.createTime,
141132
personalSign: _bioController.text,
142133
introduction: _introductionController.text,
143-
avatar: _selectedAvatar?.path ?? _currentUser!.avatar,
134+
avatar: (_selectedAvatar?.path ?? (_selectedAvatar?.bytes != null ? 'bytes' : null)) ?? _currentUser!.avatar,
144135
);
145136
_isSubmitting = false;
146137
});
@@ -181,116 +172,63 @@ class _ProfileEditScreenState extends State<ProfileEditScreen> {
181172
child: Column(
182173
crossAxisAlignment: CrossAxisAlignment.start,
183174
children: [
184-
// Background and Avatar Section
185-
AspectRatio(
186-
aspectRatio: 16 / 7,
187-
child: Stack(
188-
clipBehavior: Clip.none,
189-
fit: StackFit.expand,
190-
children: [
191-
// Background
192-
GestureDetector(
193-
onTap: _selectBackground,
194-
child: Container(
195-
color: colorScheme.surfaceContainerHigh,
196-
child: _selectedBackground != null
197-
? Image.file(
198-
File(_selectedBackground!.path),
199-
fit: BoxFit.cover,
200-
)
201-
: Center(
202-
child: Column(
203-
mainAxisAlignment: MainAxisAlignment.center,
204-
children: [
205-
Icon(
206-
Symbols.add_photo_alternate,
207-
size: 48,
208-
color: colorScheme.onSurfaceVariant,
209-
),
210-
const SizedBox(height: 8),
211-
Text(
212-
l10n.profileEditChangeBackground,
213-
style: TextStyle(
214-
color: colorScheme.onSurfaceVariant,
215-
),
216-
),
217-
],
175+
// Avatar Section
176+
Center(
177+
child: Padding(
178+
padding: const EdgeInsets.symmetric(vertical: 32),
179+
child: GestureDetector(
180+
onTap: _selectAvatar,
181+
child: Stack(
182+
clipBehavior: Clip.none,
183+
children: [
184+
Container(
185+
decoration: BoxDecoration(
186+
shape: BoxShape.circle,
187+
border: Border.all(
188+
color: colorScheme.outline.withOpacity(0.2),
189+
width: 3,
190+
),
191+
),
192+
child: _selectedAvatar != null
193+
? CircleAvatar(
194+
radius: 60,
195+
backgroundImage: kIsWeb && _selectedAvatar!.bytes != null
196+
? MemoryImage(_selectedAvatar!.bytes!)
197+
: (_selectedAvatar!.path != null
198+
? FileImage(File(_selectedAvatar!.path!)) as ImageProvider
199+
: null),
200+
)
201+
: ProfilePictureWidget(
202+
avatarUrl: _currentUser!.avatar,
203+
radius: 60,
218204
),
219-
),
220-
),
221-
),
222-
223-
// Background remove button
224-
if (_selectedBackground != null)
225-
Positioned(
226-
top: 8,
227-
right: 8,
228-
child: IconButton.filled(
229-
icon: const Icon(Symbols.delete),
230-
onPressed: _removeBackground,
231-
tooltip: l10n.profileEditRemoveBackground,
232205
),
233-
),
234-
235-
// Avatar
236-
Positioned(
237-
left: 20,
238-
bottom: -32,
239-
child: GestureDetector(
240-
onTap: _selectAvatar,
241-
child: Stack(
242-
clipBehavior: Clip.none,
243-
children: [
244-
Container(
245-
decoration: BoxDecoration(
246-
shape: BoxShape.circle,
247-
border: Border.all(
248-
color: colorScheme.surface,
249-
width: 4,
250-
),
206+
Positioned(
207+
right: 0,
208+
bottom: 0,
209+
child: Container(
210+
decoration: BoxDecoration(
211+
color: colorScheme.primaryContainer,
212+
shape: BoxShape.circle,
213+
border: Border.all(
214+
color: colorScheme.surface,
215+
width: 3,
251216
),
252-
child: _selectedAvatar != null
253-
? CircleAvatar(
254-
radius: 40,
255-
backgroundImage: FileImage(
256-
File(_selectedAvatar!.path),
257-
),
258-
)
259-
: ProfilePictureWidget(
260-
avatarUrl: _currentUser!.avatar,
261-
radius: 40,
262-
),
263217
),
264-
Positioned(
265-
right: -4,
266-
bottom: -4,
267-
child: Container(
268-
decoration: BoxDecoration(
269-
color: colorScheme.primaryContainer,
270-
shape: BoxShape.circle,
271-
border: Border.all(
272-
color: colorScheme.surface,
273-
width: 2,
274-
),
275-
),
276-
padding: const EdgeInsets.all(6),
277-
child: Icon(
278-
Symbols.edit,
279-
size: 16,
280-
color: colorScheme.onPrimaryContainer,
281-
),
282-
),
218+
padding: const EdgeInsets.all(10),
219+
child: Icon(
220+
Symbols.edit,
221+
size: 20,
222+
color: colorScheme.onPrimaryContainer,
283223
),
284-
],
224+
),
285225
),
286-
),
226+
],
287227
),
288-
],
228+
),
289229
),
290230
),
291231

292-
const SizedBox(height: 48),
293-
294232
// Basic Info Section
295233
Padding(
296234
padding: const EdgeInsets.symmetric(horizontal: 24),

0 commit comments

Comments
 (0)