-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/fe formular dotaz do odborne poradny#467 (#476)
* wip: Formular_pridanieFormScreen#467 * wip: Formular-note_text_field_with_variable_length#467 * wip: Formular-updated-UI#467 * Formular-added_new_text_fields#467 * wip: Added_finalized_UI_with_email_fetching#467 * wip: updated_to_use_with_form#467 * wip: Formular-widget_extraction_and_decomposition#467 * wip: Formular-support_for_choosing_state_in_advance#467 * Formular-Added_error_and_snackbar_text#467 * Formular-Added_errorText_support#467 * wip: Formular-Validation_and_snackbar#467 * wip: Formular-removed-errorTextParam#467 * Formular-TextStyle_extraction#467 * Formular-chip_text_extraction_to_localization#467 * Formular-Added_gesture_detector#467 * Formular-code_refactoring#467 * Formular-class_variables_made_private#467 * Formular-final_checks#467 * Formular-renamed_enum_and_removed_underscores#467 * Formular-removed_force_unwrap#467 * Formular-fix_format#467 Co-authored-by: Adam Šupej <[email protected]>
- Loading branch information
Showing
6 changed files
with
387 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:loono/ui/widgets/form/form_content.dart'; | ||
import 'package:loono/utils/hidekeyboard_util.dart'; | ||
|
||
class FormScreen extends StatelessWidget { | ||
const FormScreen({ | ||
super.key, | ||
this.initializedType = FormQuestionType.uninitialized, | ||
}); | ||
|
||
final FormQuestionType initializedType; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
backgroundColor: const Color.fromRGBO(255, 255, 255, 1), | ||
appBar: AppBar( | ||
elevation: 0.0, | ||
backgroundColor: Colors.white24, | ||
leading: IconButton( | ||
icon: const Icon( | ||
Icons.arrow_back, | ||
color: Colors.black, | ||
), | ||
onPressed: () { | ||
AutoRouter.of(context).pop(); | ||
}, | ||
), | ||
), | ||
body: SafeArea( | ||
child: GestureDetector( | ||
onTap: () => hideKeyboard(context), | ||
child: FormContent(initializedType), | ||
), | ||
), | ||
); | ||
} | ||
} |
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,182 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:loono/constants.dart'; | ||
import 'package:loono/l10n/ext.dart'; | ||
import 'package:loono/services/database_service.dart'; | ||
import 'package:loono/ui/widgets/button.dart'; | ||
import 'package:loono/ui/widgets/form/form_question_types_wrapper.dart'; | ||
import 'package:loono/ui/widgets/note_text_field.dart'; | ||
import 'package:loono/ui/widgets/space.dart'; | ||
import 'package:loono/utils/registry.dart'; | ||
|
||
enum FormQuestionType { | ||
uninitialized, | ||
selfExam, | ||
mentalHealth, | ||
preventionAndHealthStyle, | ||
heartAndVessel, | ||
reproductionalHealth, | ||
sexualHealth, | ||
preventiveExamAndScreening, | ||
other, | ||
} | ||
|
||
class FormContent extends StatefulWidget { | ||
const FormContent( | ||
this.questionType, { | ||
super.key, | ||
}); | ||
|
||
final FormQuestionType questionType; | ||
|
||
@override | ||
State<FormContent> createState() => _FormContentState(); | ||
} | ||
|
||
class _FormContentState extends State<FormContent> { | ||
final _currentUser = registry.get<DatabaseService>().users.user; | ||
final _textFieldController = TextEditingController(); | ||
late FormQuestionType _questionType; | ||
bool _wrapperError = false; | ||
bool _textInputError = false; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_questionType = widget.questionType; | ||
} | ||
|
||
void _updateQuestionType(int index) { | ||
_questionType = FormQuestionType.values[index + 1]; | ||
} | ||
|
||
void _showErrorSnackBar() { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: Text( | ||
context.l10n.form_snack_error, | ||
style: LoonoFonts.snackbarStyle, | ||
), | ||
backgroundColor: LoonoColors.errorColor, | ||
), | ||
); | ||
} | ||
|
||
void _validateFormFields() { | ||
setState(() { | ||
if (_questionType == FormQuestionType.uninitialized) { | ||
_wrapperError = true; | ||
_showErrorSnackBar(); | ||
} else { | ||
_wrapperError = false; | ||
} | ||
if (_textFieldController.text.isEmpty) { | ||
_textInputError = true; | ||
_showErrorSnackBar(); | ||
} else { | ||
_textInputError = false; | ||
} | ||
}); | ||
} | ||
|
||
void _sendForm() { | ||
_validateFormFields(); | ||
if (_questionType != FormQuestionType.uninitialized && _textFieldController.text.isNotEmpty) { | ||
// TODO: SEND FORM | ||
// final name = _currentUser?.nickname; | ||
// final sex = _currentUser?.sex; | ||
// final age = _currentUser?.dateOfBirth; | ||
// final message = _textFieldController.text; | ||
// print(name); | ||
// print(sex); | ||
// print(age); | ||
// print(message); | ||
// print(_questionType); | ||
AutoRouter.of(context).popUntilRoot(); | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: Text( | ||
context.l10n.form_snack_success, | ||
style: LoonoFonts.snackbarStyle, | ||
), | ||
backgroundColor: LoonoColors.greenSuccess, | ||
), | ||
); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
Expanded( | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: 18, | ||
), | ||
child: SingleChildScrollView( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text( | ||
context.l10n.form_specialist_question, | ||
style: LoonoFonts.headerFontStyle, | ||
), | ||
const CustomSpacer.vertical(30), | ||
Text( | ||
context.l10n.form_question_answer('"${_currentUser?.email}"'), | ||
style: LoonoFonts.paragraphFontStyle, | ||
), | ||
const Divider( | ||
height: 60, | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only(bottom: 20), | ||
child: Text( | ||
context.l10n.form_question_field, | ||
style: LoonoFonts.subtitleFontStyle, | ||
), | ||
), | ||
FormQuestionTypesWrapper( | ||
_questionType.index == 0 ? null : _questionType.index - 1, | ||
_updateQuestionType, | ||
), | ||
if (_wrapperError) | ||
Padding( | ||
padding: const EdgeInsets.only(left: 15), | ||
child: Text( | ||
context.l10n.form_wrapper_error, | ||
style: LoonoFonts.errorMessageStyle, | ||
), | ||
), | ||
const CustomSpacer.vertical(30), | ||
noteTextField( | ||
context, | ||
noteController: _textFieldController, | ||
onNoteChange: null, | ||
maxLength: 700, | ||
isForm: true, | ||
error: _textInputError, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only( | ||
top: 30, | ||
bottom: 70, | ||
left: 18, | ||
right: 18, | ||
), | ||
child: LoonoButton( | ||
onTap: _sendForm, | ||
text: context.l10n.form_send_question, | ||
), | ||
) | ||
], | ||
); | ||
} | ||
} |
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,84 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:loono/constants.dart'; | ||
import 'package:loono/l10n/ext.dart'; | ||
|
||
class FormQuestionTypesWrapper extends StatefulWidget { | ||
const FormQuestionTypesWrapper( | ||
this.defaultChipIndex, | ||
this.updateQuestionType, { | ||
super.key, | ||
}); | ||
|
||
final Function updateQuestionType; | ||
final int? defaultChipIndex; | ||
|
||
@override | ||
State<FormQuestionTypesWrapper> createState() => _FormQuestionTypesWrapperState(); | ||
} | ||
|
||
class _FormQuestionTypesWrapperState extends State<FormQuestionTypesWrapper> { | ||
late List<String> _choices; | ||
late Function _updateQuestionType; | ||
int? _activeChipIndex; | ||
bool _initialized = false; | ||
|
||
@override | ||
void didChangeDependencies() { | ||
if (!_initialized) { | ||
_initialized = true; | ||
_choices = [ | ||
context.l10n.form_self_exam, | ||
context.l10n.form_mentalHealth, | ||
context.l10n.form_preventionAndHealthStyle, | ||
context.l10n.form_heartAndVessel, | ||
context.l10n.form_reproductionalHealth, | ||
context.l10n.form_sexualHealth, | ||
context.l10n.form_preventiveExamAndScreening, | ||
context.l10n.form_other, | ||
]; | ||
_updateQuestionType = widget.updateQuestionType; | ||
_activeChipIndex = widget.defaultChipIndex; | ||
} | ||
super.didChangeDependencies(); | ||
} | ||
|
||
void _updateState(bool value, int index) { | ||
if (value) { | ||
setState(() { | ||
_updateQuestionType(index); | ||
_activeChipIndex = index; | ||
}); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Wrap( | ||
children: List.generate(_choices.length, (index) { | ||
return Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 5), | ||
child: ChoiceChip( | ||
avatar: index == _activeChipIndex | ||
? const Icon( | ||
Icons.check, | ||
color: LoonoColors.primaryEnabled, | ||
) | ||
: null, | ||
label: Text( | ||
_choices[index], | ||
style: index == _activeChipIndex | ||
? LoonoFonts.chipStyleActive | ||
: LoonoFonts.chipStyleDefault, | ||
), | ||
selected: index == _activeChipIndex, | ||
selectedColor: LoonoColors.beigeLight, | ||
onSelected: (value) { | ||
_updateState(value, index); | ||
}, | ||
), | ||
); | ||
}), | ||
); | ||
} | ||
} |
Oops, something went wrong.