-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete account view with basic bloc (#296)
* Delete account view with basic bloc * Delete account bloc logic * Fix delete account logic * Extract delete account button to separate widget * Extract delete account button to separate widget * Fix const login route * Regenerated pod lockfile * Remove empty app router file * Fix lint * Update copy on delete page * Regenerated pod lockfile --------- Co-authored-by: kackogut <[email protected]> Co-authored-by: James Elgar <[email protected]> Co-authored-by: JElgar <[email protected]>
- Loading branch information
1 parent
8ded766
commit f8896d2
Showing
8 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:nowu/router.gr.dart'; | ||
import 'package:nowu/ui/views/delete_account/delete_account_state.dart'; | ||
|
||
import '../../../services/auth.dart'; | ||
import '../../../services/user_service.dart'; | ||
|
||
const String deleteUserConfirmationText = 'delete me'; | ||
|
||
class DeleteAccountBloc extends Cubit<DeleteAccountState> { | ||
AuthenticationService _authenticationService; | ||
StackRouter _appRouter; | ||
UserService _userService; | ||
|
||
DeleteAccountBloc({ | ||
required AuthenticationService authenticationService, | ||
required StackRouter appRouter, | ||
required UserService userService, | ||
}) : _authenticationService = authenticationService, | ||
_appRouter = appRouter, | ||
_userService = userService, | ||
super(const DeleteAccountState()); | ||
|
||
void updateInputName(String name) { | ||
emit( | ||
state.copyWith( | ||
name: name, | ||
isNameValid: name == deleteUserConfirmationText, | ||
), | ||
); | ||
} | ||
|
||
Future<void> deleteAccount() async { | ||
if (!state.isNameValid) return; | ||
|
||
await _userService.deleteUser(); | ||
await _authenticationService.logout(); | ||
_appRouter.pushAndPopUntil(LoginRoute(), predicate: (r) => false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'delete_account_state.freezed.dart'; | ||
|
||
@freezed | ||
class DeleteAccountState with _$DeleteAccountState { | ||
const factory DeleteAccountState({ | ||
@Default('') String name, | ||
@Default(false) bool isNameValid, | ||
}) = _DeleteAccountState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
import '../../../locator.dart'; | ||
import '../../../services/auth.dart'; | ||
import '../../../services/user_service.dart'; | ||
import 'delete_account_bloc.dart'; | ||
import 'delete_account_state.dart'; | ||
|
||
@RoutePage() | ||
class DeleteAccountView extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
DeleteAccountBloc bloc = DeleteAccountBloc( | ||
authenticationService: locator<AuthenticationService>(), | ||
appRouter: AutoRouter.of(context), | ||
userService: locator<UserService>(), | ||
); | ||
|
||
return BlocProvider<DeleteAccountBloc>( | ||
create: (_) => bloc, | ||
child: Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Delete Account'), | ||
), | ||
body: Container( | ||
color: Colors.white, | ||
child: Center( | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 20), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
RichText( | ||
textAlign: TextAlign.center, | ||
text: TextSpan( | ||
style: Theme.of(context).textTheme.titleMedium, | ||
children: [ | ||
const TextSpan( | ||
text: | ||
'Are you sure you want to delete your account? ', | ||
), | ||
const TextSpan( | ||
text: 'This action cannot be undone.', | ||
style: TextStyle(fontWeight: FontWeight.w700), | ||
), | ||
], | ||
), | ||
), | ||
const SizedBox(height: 8), | ||
Text( | ||
'To confirm, please type "$deleteUserConfirmationText" below.', | ||
style: Theme.of(context).textTheme.titleMedium, | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 8), | ||
TextField( | ||
onChanged: bloc.updateInputName, | ||
decoration: const InputDecoration( | ||
hintText: deleteUserConfirmationText, | ||
), | ||
), | ||
const SizedBox(height: 8), | ||
DeleteAccountButton(), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class DeleteAccountButton extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return BlocBuilder<DeleteAccountBloc, DeleteAccountState>( | ||
builder: (context, state) { | ||
return ElevatedButton( | ||
onPressed: state.isNameValid | ||
? context.read<DeleteAccountBloc>().deleteAccount | ||
: null, | ||
child: const Text('Delete Account'), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,7 @@ paths: | |
- tr | ||
- tt | ||
- udm | ||
- ug | ||
- uk | ||
- ur | ||
- uz | ||
|