Skip to content

Commit

Permalink
Extract delete account button to separate widget
Browse files Browse the repository at this point in the history
  • Loading branch information
kackogut committed Aug 8, 2024
1 parent fdb87d7 commit a647f3a
Showing 1 changed file with 60 additions and 44 deletions.
104 changes: 60 additions & 44 deletions lib/ui/views/delete_account/delete_account_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,69 @@ class DeleteAccountView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => DeleteAccountBloc(
authenticationService: locator<AuthenticationService>(),
appRouter: AutoRouter.of(context),
userService: locator<UserService>(),
),
child: BlocBuilder<DeleteAccountBloc, DeleteAccountState>(
builder: (context, state) {
return Scaffold(
appBar: AppBar(
title: 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>[
Text(
'Are you sure you want to delete your account? This action cannot be undone.',
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.center,
),
const Padding(padding: EdgeInsets.all(8)),
TextField(
onChanged:
context.read<DeleteAccountBloc>().updateInputName,
decoration: const InputDecoration(
hintText: 'Type account name to confirm',
),
),
const Padding(padding: EdgeInsets.all(8)),
ElevatedButton(
onPressed: state.isNameValid
? context.read<DeleteAccountBloc>().deleteAccount
: null,
child: Text('Delete Account'),
),
],
create: (_) =>
DeleteAccountBloc(
authenticationService: locator<AuthenticationService>(),
appRouter: AutoRouter.of(context),
userService: locator<UserService>(),
),
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>[
Text(
'Are you sure you want to delete your account? This action cannot be undone.',
style: Theme
.of(context)
.textTheme
.titleMedium,
textAlign: TextAlign.center,
),
const Padding(padding: EdgeInsets.all(8)),
TextField(
onChanged:
context
.read<DeleteAccountBloc>()
.updateInputName,
decoration: const InputDecoration(
hintText: 'Type account name to confirm',
),
),
),
const Padding(padding: EdgeInsets.all(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'),
);
},
);
}
}

0 comments on commit a647f3a

Please sign in to comment.