Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/view/components/settings/edit_input_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ class EditInputText extends StatefulWidget {
final String label;
final void Function(String value) onChanged;
final String input;
final int maxLines;
final int maxLength;
final Key inputKey;
final bool validate;

const EditInputText(
{super.key,
required this.maxLines,
required this.maxLength,
required this.label,
required this.onChanged,
required this.input,
required this.inputKey});
required this.inputKey,
required this.validate});

@override
State<EditInputText> createState() => _EditInputText();
Expand Down Expand Up @@ -56,7 +58,18 @@ class _EditInputText extends State<EditInputText> {
),
initialValue: widget.input,
style: TextStyle(color: Theme.of(context).colorScheme.secondary, fontSize: 12),
maxLines: widget.maxLines,
maxLength: widget.maxLength,
validator: widget.validate?(value) {
if (value == null || value.isEmpty) {
return 'Please enter a username';
}
if (!RegExp(r'^[a-zA-Z ]+$').hasMatch(value)) {
return 'Only alphabetical letters are permitted';
}
return null;
}: (value){
return null;
},
),
],
),
Expand Down
1 change: 1 addition & 0 deletions lib/view/pages/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class _HomePageState extends State<HomePage> {
content: Form(
key: _formKey,
child: TextFormField(
maxLength: 16,
key: Key('usernameInput'),
autofocus: true,
controller: usernamecontroller,
Expand Down
12 changes: 8 additions & 4 deletions lib/view/pages/settings/edit_profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,11 @@ class _EditProfilePage extends State<EditProfilePage> {
children: [
EditInputText(
inputKey: const Key('usernameField'),
maxLines: 1,
maxLength: 16,
label: 'Username',
onChanged: (value) => _username = value,
input: _username,
validate: true,
),
Row(
mainAxisAlignment:
Expand All @@ -371,28 +372,31 @@ class _EditProfilePage extends State<EditProfilePage> {
Flexible(
child: EditInputText(
inputKey: const Key('firstNameField'),
maxLines: 1,
maxLength: 16,
label: 'First name',
onChanged: (value) => _firstName = value,
input: _firstName,
validate: true,
),
),
Flexible(
child: EditInputText(
inputKey: const Key('lastNameField'),
maxLines: 1,
maxLength: 16,
label: 'Last Name',
onChanged: (value) => _lastName = value,
input: _lastName,
validate: true,
),
),
]),
EditInputText(
inputKey: const Key('bioField'),
maxLines: 5,
maxLength: 100,
label: 'Bio',
onChanged: (value) => _bio = value,
input: _bio,
validate: false,
),
EditDateInput(
currentDate: _birthday!,
Expand Down
Loading