Skip to content

Commit

Permalink
feat: add delete account UI
Browse files Browse the repository at this point in the history
  • Loading branch information
SungyeopJeong authored and sboh1214 committed Aug 16, 2023
1 parent b3d8940 commit b0dec43
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 17 deletions.
4 changes: 3 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@
"major": "Major",
"my_review": "My Reviews",
"liked_review": "Liked Reviews",
"logout": "Logout"
"logout": "Logout",
"delete_account": "Delete Account",
"ask_delete_account": "Are you sure you want to delete your account?"
},
"settings": {
"send_error_log": "Send error log",
Expand Down
4 changes: 3 additions & 1 deletion assets/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@
"major": "전공",
"my_review": "내가 들은 과목",
"liked_review": "좋아요한 후기",
"logout": "로그아웃"
"logout": "로그아웃",
"delete_account": "계정 삭제",
"ask_delete_account": "계정을 정말 삭제하시겠습니까?"
},
"settings": {
"send_error_log": "오류 로그 전송",
Expand Down
60 changes: 45 additions & 15 deletions lib/pages/user_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:otlplus/providers/auth_model.dart';
import 'package:otlplus/utils/build_app_bar.dart';
import 'package:otlplus/utils/build_page_route.dart';
import 'package:otlplus/utils/responsive_button.dart';
import 'package:otlplus/widgets/delete_dialog.dart';
import 'package:provider/provider.dart';
import 'package:otlplus/constants/color.dart';
import 'package:otlplus/providers/info_model.dart';
Expand Down Expand Up @@ -57,21 +58,35 @@ class UserPage extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: _buildDivider(),
),
Align(
alignment: Alignment.centerLeft,
child: IconTextButton(
icon: 'assets/icons/logout.svg',
onTap: () {
context.read<AuthModel>().logout();
context.read<InfoModel>().logout();
Navigator.pop(context);
},
text: 'user.logout'.tr(),
color: OTLColor.pinksMain,
textStyle: bodyBold,
spaceBetween: 8.0,
padding: EdgeInsets.symmetric(horizontal: 16.0),
),
_buildAccount(
'assets/icons/logout.svg',
() {
context.read<AuthModel>().logout();
context.read<InfoModel>().logout();
Navigator.pop(context);
},
'user.logout'.tr(),
),
_buildAccount(
Icons.highlight_off,
() async {
showGeneralDialog(
context: context,
barrierColor: Colors.black.withOpacity(0.2),
barrierDismissible: true,
barrierLabel: MaterialLocalizations.of(context)
.modalBarrierDismissLabel,
pageBuilder: (context, _, __) => DeleteDialog(
text: 'user.ask_delete_account'.tr(),
onDelete: () {
context.read<AuthModel>().logout();
context.read<InfoModel>().deleteAccount();
Navigator.pop(context);
},
),
);
},
'user.delete_account'.tr(),
),
],
),
Expand Down Expand Up @@ -150,4 +165,19 @@ class UserPage extends StatelessWidget {
onTap: onTap,
);
}

Widget _buildAccount(dynamic icon, void Function()? onTap, String? text) {
return Align(
alignment: Alignment.centerLeft,
child: IconTextButton(
icon: icon,
onTap: onTap,
text: text,
color: OTLColor.pinksMain,
textStyle: bodyBold,
spaceBetween: 8.0,
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 6.0),
),
);
}
}
5 changes: 5 additions & 0 deletions lib/providers/info_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,9 @@ class InfoModel extends ChangeNotifier {
return schedules.firstWhere((e) => e!["time"].isAfter(now),
orElse: () => null);
}

void deleteAccount() {
_hasData = false;
notifyListeners();
}
}

0 comments on commit b0dec43

Please sign in to comment.