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