1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 14:59:22 +00:00

Improve security questions form

This commit is contained in:
Pierre HUBERT 2020-05-03 15:48:10 +02:00
parent e78d526bbb
commit 3ffb24f7c5

View File

@ -19,12 +19,15 @@ class ResetPasswordRoute extends StatelessWidget {
appBar: AppBar( appBar: AppBar(
title: Text(tr("Password forgotten")), title: Text(tr("Password forgotten")),
), ),
body: Center( body: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 300), constraints: BoxConstraints(maxWidth: 300),
child: SingleChildScrollView(child: _ResetPasswordBody()), child: SingleChildScrollView(child: _ResetPasswordBody()),
), ),
), ),
),
); );
} }
} }
@ -59,6 +62,11 @@ class _ResetPasswordBodyState extends SafeState<_ResetPasswordBody> {
List<String> _questions; List<String> _questions;
var _questionsControllers = List<TextEditingController>(); var _questionsControllers = List<TextEditingController>();
List<String> get _answers =>
_questionsControllers.map((f) => f.text).toList();
bool get _canSubmitAnswers => _answers.every((f) => f.isNotEmpty);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_loading) return buildCenteredProgressBar(); if (_loading) return buildCenteredProgressBar();
@ -189,19 +197,30 @@ class _ResetPasswordBodyState extends SafeState<_ResetPasswordBody> {
..addAll(List.generate(_questions.length, _buildSecurityQuestionField)) ..addAll(List.generate(_questions.length, _buildSecurityQuestionField))
..add(_Spacer()) ..add(_Spacer())
..add(OutlineButton( ..add(OutlineButton(
onPressed: null, onPressed: _canSubmitAnswers ? _submitSecurityAnswers : null,
child: Text(tr("Submit")), child: Text(tr("Submit")),
)), )),
); );
} }
Widget _buildSecurityQuestionField(int id) => TextField( Widget _buildSecurityQuestionField(int id) => Column(
children: <Widget>[
Text(_questions[id]),
TextField(
controller: _questionsControllers[id], controller: _questionsControllers[id],
onChanged: (s) => setState(() {}),
onSubmitted:
_canSubmitAnswers ? (s) => _submitSecurityAnswers() : null,
decoration: InputDecoration( decoration: InputDecoration(
alignLabelWithHint: true, alignLabelWithHint: false,
labelText: _questions[id], labelText: tr("Answer %num%", args: {"num": id.toString()})),
), ),
_Spacer()
],
); );
/// Submit security answers
Future<void> _submitSecurityAnswers() async {}
} }
class _Spacer extends StatelessWidget { class _Spacer extends StatelessWidget {