Expandable Language List

master
Rafael 2024-06-20 22:26:47 +02:00
parent 63178cbcbc
commit e79bfd5b7e
1 changed files with 44 additions and 6 deletions

View File

@ -47,6 +47,8 @@ class _UserDataPageState extends State<UserDataPage> {
MyLocation? _mainLocationFromDb; MyLocation? _mainLocationFromDb;
MyLocation? _secondaryLocationFromDb; MyLocation? _secondaryLocationFromDb;
bool _secondLocationExists = false; bool _secondLocationExists = false;
bool _isLanguageListExpanded = false;
static const int _initialLanguageListItemCount = 5;
@override @override
void initState() { void initState() {
@ -367,8 +369,8 @@ class _UserDataPageState extends State<UserDataPage> {
} else { } else {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: title: Text(
Text('${widget.isRegProcess ? 'About you' : 'Edit your data'} '), '${widget.isRegProcess ? 'Personal Details' : 'Edit your details'} '),
centerTitle: true, centerTitle: true,
actions: [ actions: [
if (widget.isEditMode && !widget.isRegProcess) if (widget.isEditMode && !widget.isRegProcess)
@ -471,7 +473,12 @@ class _UserDataPageState extends State<UserDataPage> {
], ],
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
const TextBold(text: 'Age'), const TextWithBold(
boldText: 'Age ',
trailingText: ' (optional)',
boldSize: 18,
trailingSize: 12,
),
Row( Row(
children: [ children: [
const Padding(padding: EdgeInsets.symmetric(horizontal: 8)), const Padding(padding: EdgeInsets.symmetric(horizontal: 8)),
@ -534,10 +541,16 @@ class _UserDataPageState extends State<UserDataPage> {
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
const Divider(), const Divider(),
TextBold( Row(
text: 'Language: (${_selectedLanguages.length} selected)', mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextBold(
text: 'Language: (${_selectedLanguages.length} selected)',
),
_buildExpandCollapseButton(),
],
), ),
...languagesList.map(buildSingleCheckbox), ..._buildLanguageList(),
const Divider(), const Divider(),
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
@ -555,6 +568,31 @@ class _UserDataPageState extends State<UserDataPage> {
} }
} }
List<Widget> _buildLanguageList() {
List<LanguageSetting> displayedLanguages = _isLanguageListExpanded
? languagesList
: languagesList.take(_initialLanguageListItemCount).toList();
return displayedLanguages.map(buildSingleCheckbox).toList();
}
Widget _buildExpandCollapseButton() {
if (languagesList.length <= _initialLanguageListItemCount) {
return Container();
}
return TextButton(
onPressed: () {
setState(() {
_isLanguageListExpanded = !_isLanguageListExpanded;
});
},
child: Text(
_isLanguageListExpanded ? 'Show less languages' : 'Show more languages',
),
);
}
Widget buildSingleCheckbox(LanguageSetting languageSetting) => buildCheckbox( Widget buildSingleCheckbox(LanguageSetting languageSetting) => buildCheckbox(
languageSetting: languageSetting, languageSetting: languageSetting,
onClicked: () { onClicked: () {