D1APP-78 delete user profile
This commit is contained in:
parent
5b578540a5
commit
6d5548362c
|
|
@ -43,11 +43,11 @@ class User {
|
|||
}) {
|
||||
return User(
|
||||
id: id ?? this.id,
|
||||
username: username ?? this.username,
|
||||
username: this.username,
|
||||
phoneNumber: phoneNumber ?? this.phoneNumber,
|
||||
photo: photo ?? this.photo,
|
||||
photo: photo,
|
||||
fullName: fullName ?? this.fullName,
|
||||
email: email ?? this.email,
|
||||
email: email,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class ActionSheetData {
|
|||
final IconData? titleIcon;
|
||||
final Color? titleColor;
|
||||
final bool hasDismissButton;
|
||||
final bool hasConfirmButton;
|
||||
final bool withoutButtonMode;
|
||||
final bool smallDismissButton;
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ class ActionSheetData {
|
|||
this.onConfirmed,
|
||||
this.titleColor,
|
||||
this.hasDismissButton = true,
|
||||
this.hasConfirmButton = true,
|
||||
this.titleIcon,
|
||||
this.dismissTitle,
|
||||
this.onDismissed,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:didvan/config/theme_data.dart';
|
||||
import 'package:didvan/constants/app_icons.dart';
|
||||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/view/action_sheet_data.dart';
|
||||
import 'package:didvan/models/view/alert_data.dart';
|
||||
import 'package:didvan/pages/home/widgets/menu_item.dart';
|
||||
import 'package:didvan/providers/user_provider.dart';
|
||||
|
|
@ -78,37 +79,62 @@ class _ProfilePhotoState extends State<ProfilePhoto> {
|
|||
|
||||
Future<void> _openImagePickerSheet() async {
|
||||
FocusScope.of(context).unfocus();
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) => DidvanCard(
|
||||
enableBorder: false,
|
||||
child: Column(
|
||||
await ActionSheetUtils.showBottomSheet(
|
||||
data: ActionSheetData(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const DidvanText('بارگذاری تصویر از:'),
|
||||
const SizedBox(height: 16),
|
||||
MenuItem(
|
||||
title: 'دوربین',
|
||||
onTap: () => _setProfilePhoto(ImageSource.camera),
|
||||
icon: DidvanIcons.camera_regular,
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
MenuItem(
|
||||
title: 'دوربین',
|
||||
onTap: () => _setProfilePhoto(ImageSource.camera),
|
||||
icon: DidvanIcons.camera_regular,
|
||||
),
|
||||
const DidvanDivider(),
|
||||
MenuItem(
|
||||
title: 'گالری',
|
||||
onTap: () => _setProfilePhoto(ImageSource.gallery),
|
||||
icon: DidvanIcons.gallery_file_regular,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const DidvanDivider(),
|
||||
MenuItem(
|
||||
title: 'گالری',
|
||||
onTap: () => _setProfilePhoto(ImageSource.gallery),
|
||||
icon: DidvanIcons.gallery_file_regular,
|
||||
title: 'حذف تصویر',
|
||||
onTap: () => _setProfilePhoto(null),
|
||||
icon: DidvanIcons.trash_solid,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
],
|
||||
),
|
||||
hasConfirmButton: false,
|
||||
hasDismissButton: false,
|
||||
title: 'بارگذاری تصویر از:',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _setProfilePhoto(ImageSource source) async {
|
||||
Future<void> _setProfilePhoto(ImageSource? source) async {
|
||||
ActionSheetUtils.pop();
|
||||
final state = context.read<UserProvider>();
|
||||
if (source == null) {
|
||||
final result = await state.deleteProfilePhoto();
|
||||
ActionSheetUtils.showAlert(
|
||||
AlertData(
|
||||
message:
|
||||
result ? 'تصویر پروفایل حذف شد.' : 'حذف تصویر موفقیت آمیز نبود.',
|
||||
aLertType: result ? ALertType.success : ALertType.error,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final pickedFile = await MediaService.pickImage(source: source);
|
||||
if (pickedFile != null) {
|
||||
ActionSheetUtils.showLogoLoadingIndicator();
|
||||
|
|
@ -119,7 +145,6 @@ class _ProfilePhotoState extends State<ProfilePhoto> {
|
|||
arguments: {
|
||||
'bytes': bytes,
|
||||
'onCropped': () async {
|
||||
final state = context.read<UserProvider>();
|
||||
final result = await state.setProfilePhoto(pickedFile);
|
||||
ActionSheetUtils.showAlert(
|
||||
AlertData(
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class UserProvider extends CoreProvier {
|
|||
Future<bool> setProfilePhoto(dynamic file) async {
|
||||
appState = AppState.isolatedBusy;
|
||||
final RequestService service =
|
||||
RequestService(RequestHelper.updateUserProfile);
|
||||
RequestService(RequestHelper.updateProfilePhoto);
|
||||
await service.multipart(file, 'PUT');
|
||||
if (service.isSuccess) {
|
||||
user = user.copyWith(photo: service.result['photo']);
|
||||
|
|
@ -47,6 +47,20 @@ class UserProvider extends CoreProvier {
|
|||
return false;
|
||||
}
|
||||
|
||||
Future<bool> deleteProfilePhoto() async {
|
||||
appState = AppState.isolatedBusy;
|
||||
final RequestService service =
|
||||
RequestService(RequestHelper.updateProfilePhoto);
|
||||
await service.delete();
|
||||
if (service.isSuccess) {
|
||||
user = user.copyWith(photo: null);
|
||||
appState = AppState.idle;
|
||||
return true;
|
||||
}
|
||||
appState = AppState.failed;
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<bool?> checkUsername(String username) async {
|
||||
if (user.username == username) return true;
|
||||
final RequestService service = RequestService(
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class RequestHelper {
|
|||
static const String login = _baseUserUrl + '/login';
|
||||
static const String directs = _baseUserUrl + '/direct';
|
||||
static const String userInfo = _baseUserUrl + '/info';
|
||||
static const String updateUserProfile = _baseUserUrl + '/profile/photo';
|
||||
static const String updateProfilePhoto = _baseUserUrl + '/profile/photo';
|
||||
static const String checkUsername = _baseUserUrl + '/CheckUsername';
|
||||
static const String updateProfile = _baseUserUrl + '/profile/edit';
|
||||
static String bookmarks({String? type}) =>
|
||||
|
|
|
|||
|
|
@ -83,9 +83,7 @@ class ActionSheetUtils {
|
|||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(
|
||||
10,
|
||||
),
|
||||
top: Radius.circular(10),
|
||||
),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
|
|
@ -136,17 +134,18 @@ class ActionSheetUtils {
|
|||
),
|
||||
),
|
||||
if (data.hasDismissButton) const SizedBox(width: 20),
|
||||
Expanded(
|
||||
flex: data.smallDismissButton ? 2 : 1,
|
||||
child: DidvanButton(
|
||||
style: ButtonStyleMode.primary,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
data.onConfirmed?.call();
|
||||
},
|
||||
title: data.confrimTitle ?? 'تایید',
|
||||
if (data.hasConfirmButton)
|
||||
Expanded(
|
||||
flex: data.smallDismissButton ? 2 : 1,
|
||||
child: DidvanButton(
|
||||
style: ButtonStyleMode.primary,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
data.onConfirmed?.call();
|
||||
},
|
||||
title: data.confrimTitle ?? 'تایید',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue