Skip to content

Commit 3a21cbd

Browse files
committed
DEV-43330
1 parent 15edcdb commit 3a21cbd

File tree

7 files changed

+47
-10
lines changed

7 files changed

+47
-10
lines changed

lib/app/data/database.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class AppDataStore extends _$AppDataStore {
245245
}
246246

247247
@override
248-
int get schemaVersion => 38;
248+
int get schemaVersion => 39;
249249

250250
@override
251251
MigrationStrategy get migration => MigrationStrategy(

lib/app/pages/person/person_page.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class _PersonViewState extends State<_PersonView> {
6969
case PersonStateStatus.failure:
7070
Misc.showMessage(context, state.message);
7171
break;
72-
case PersonStateStatus.loggedOut:
72+
case PersonStateStatus.success:
7373
progressDialog.close();
7474
WidgetsBinding.instance.addPostFrameCallback((_) {
7575
Navigator.of(context).pop();
@@ -133,6 +133,14 @@ class _PersonViewState extends State<_PersonView> {
133133
mainAxisAlignment: MainAxisAlignment.spaceAround,
134134
crossAxisAlignment: CrossAxisAlignment.center,
135135
children: <Widget>[
136+
ElevatedButton(
137+
style: ElevatedButton.styleFrom(
138+
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18.0)),
139+
backgroundColor: Theme.of(context).colorScheme.primary
140+
),
141+
onPressed: vm.apiUnregister,
142+
child: const Text('Удалить аккаунт', style: Styles.formStyle),
143+
),
136144
ElevatedButton(
137145
style: ElevatedButton.styleFrom(
138146
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18.0)),

lib/app/pages/person/person_state.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ enum PersonStateStatus {
44
initial,
55
dataLoaded,
66
inProgress,
7-
loggedOut,
7+
success,
88
failure
99
}
1010

lib/app/pages/person/person_view_model.dart

+21-4
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,30 @@ class PersonViewModel extends PageViewModel<PersonState, PersonStateStatus> {
4747

4848
try {
4949
await usersRepository.logout();
50-
await pointsRepository.clearFiles();
51-
await ordersRepository.clearFiles();
52-
await appRepository.clearData();
50+
await clearData();
5351

54-
emit(state.copyWith(status: PersonStateStatus.loggedOut));
52+
emit(state.copyWith(status: PersonStateStatus.success));
5553
} on AppError catch(e) {
5654
emit(state.copyWith(status: PersonStateStatus.failure, message: e.message));
5755
}
5856
}
57+
58+
Future<void> apiUnregister() async {
59+
emit(state.copyWith(status: PersonStateStatus.inProgress));
60+
61+
try {
62+
await usersRepository.unregister();
63+
await clearData();
64+
65+
emit(state.copyWith(status: PersonStateStatus.success));
66+
} on AppError catch(e) {
67+
emit(state.copyWith(status: PersonStateStatus.failure, message: e.message));
68+
}
69+
}
70+
71+
Future<void> clearData() async {
72+
await pointsRepository.clearFiles();
73+
await ordersRepository.clearFiles();
74+
await appRepository.clearData();
75+
}
5976
}

lib/app/repositories/users_repository.dart

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ class UsersRepository extends BaseRepository {
4949
await loadUserData();
5050
}
5151

52+
Future<void> unregister() async {
53+
try {
54+
await api.unregister();
55+
_loggedInController.add(api.isLoggedIn);
56+
} on ApiException catch(e) {
57+
throw AppError(e.errorMsg);
58+
} catch(e, trace) {
59+
await Misc.reportError(e, trace);
60+
throw AppError(Strings.genericErrorMsg);
61+
}
62+
}
63+
5264
Future<void> login(String url, String login, String password) async {
5365
try {
5466
await api.login(url: url, login: login, password: password);

pubspec.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1548,8 +1548,8 @@ packages:
15481548
dependency: "direct main"
15491549
description:
15501550
path: "."
1551-
ref: "75821c5"
1552-
resolved-ref: "75821c5922271d4afc92169f9cf2dbff142f984a"
1551+
ref: "39b77cc"
1552+
resolved-ref: "39b77cc44408eb0eae971d4986c8f214b31f0b32"
15531553
url: "[email protected]:Unact/u_app_utils.git"
15541554
source: git
15551555
version: "0.0.1"

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ dependencies:
4949
u_app_utils:
5050
git:
5151
url: [email protected]:Unact/u_app_utils.git
52-
ref: 75821c5
52+
ref: 39b77cc
5353
url_launcher: ^6.3.1
5454
uuid: ^4.2.2
5555
yandex_mapkit: ^4.0.2

0 commit comments

Comments
 (0)