1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 06:49: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,10 +19,13 @@ class ResetPasswordRoute extends StatelessWidget {
appBar: AppBar( appBar: AppBar(
title: Text(tr("Password forgotten")), title: Text(tr("Password forgotten")),
), ),
body: Center( body: Padding(
child: ConstrainedBox( padding: const EdgeInsets.all(8.0),
constraints: BoxConstraints(maxWidth: 300), child: Center(
child: SingleChildScrollView(child: _ResetPasswordBody()), child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 300),
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(
controller: _questionsControllers[id], children: <Widget>[
decoration: InputDecoration( Text(_questions[id]),
alignLabelWithHint: true, TextField(
labelText: _questions[id], 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<void> _submitSecurityAnswers() async {}
} }
class _Spacer extends StatelessWidget { class _Spacer extends StatelessWidget {