From 3ffb24f7c5d958cb1bfa47b946d90da5931c9063 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 3 May 2020 15:48:10 +0200 Subject: [PATCH] Improve security questions form --- lib/ui/routes/reset_password_route.dart | 41 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/ui/routes/reset_password_route.dart b/lib/ui/routes/reset_password_route.dart index 0946412..6eab5f8 100644 --- a/lib/ui/routes/reset_password_route.dart +++ b/lib/ui/routes/reset_password_route.dart @@ -19,10 +19,13 @@ class ResetPasswordRoute extends StatelessWidget { appBar: AppBar( title: Text(tr("Password forgotten")), ), - body: Center( - child: ConstrainedBox( - constraints: BoxConstraints(maxWidth: 300), - child: SingleChildScrollView(child: _ResetPasswordBody()), + body: Padding( + padding: const EdgeInsets.all(8.0), + child: Center( + child: ConstrainedBox( + constraints: BoxConstraints(maxWidth: 300), + child: SingleChildScrollView(child: _ResetPasswordBody()), + ), ), ), ); @@ -59,6 +62,11 @@ class _ResetPasswordBodyState extends SafeState<_ResetPasswordBody> { List _questions; var _questionsControllers = List(); + List get _answers => + _questionsControllers.map((f) => f.text).toList(); + + bool get _canSubmitAnswers => _answers.every((f) => f.isNotEmpty); + @override Widget build(BuildContext context) { if (_loading) return buildCenteredProgressBar(); @@ -189,19 +197,30 @@ class _ResetPasswordBodyState extends SafeState<_ResetPasswordBody> { ..addAll(List.generate(_questions.length, _buildSecurityQuestionField)) ..add(_Spacer()) ..add(OutlineButton( - onPressed: null, + onPressed: _canSubmitAnswers ? _submitSecurityAnswers : null, child: Text(tr("Submit")), )), ); } - Widget _buildSecurityQuestionField(int id) => TextField( - controller: _questionsControllers[id], - decoration: InputDecoration( - alignLabelWithHint: true, - labelText: _questions[id], - ), + Widget _buildSecurityQuestionField(int id) => Column( + children: [ + Text(_questions[id]), + TextField( + controller: _questionsControllers[id], + onChanged: (s) => setState(() {}), + onSubmitted: + _canSubmitAnswers ? (s) => _submitSecurityAnswers() : null, + decoration: InputDecoration( + alignLabelWithHint: false, + labelText: tr("Answer %num%", args: {"num": id.toString()})), + ), + _Spacer() + ], ); + + /// Submit security answers + Future _submitSecurityAnswers() async {} } class _Spacer extends StatelessWidget {