fix: post creation inputfields

This commit is contained in:
mike doornenbal 2024-08-01 09:57:21 +02:00
parent 1dc79b8d74
commit 49f0853cca
2 changed files with 11 additions and 1 deletions

View file

@ -67,12 +67,15 @@ class _TimelinePostCreationScreenState
void _listenForInputs() {
titleIsValid = titleController.text.isNotEmpty;
contentIsValid = contentController.text.isNotEmpty;
setState(() {});
}
var formkey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
var imageRequired = widget.options.requireImageForPost;
Future<void> onPostCreated() async {
var post = TimelinePost(
id: 'Post${Random().nextInt(1000)}',
@ -121,6 +124,7 @@ class _TimelinePostCreationScreenState
'',
) ??
PostCreationTextfield(
fieldKey: const ValueKey('title'),
controller: titleController,
hintText: widget.options.translations.titleHintText,
textMaxLength: widget.options.maxTitleLength,
@ -152,6 +156,7 @@ class _TimelinePostCreationScreenState
height: 4,
),
PostCreationTextfield(
fieldKey: const ValueKey('content'),
controller: contentController,
hintText: widget.options.translations.contentHintText,
textMaxLength: null,
@ -355,7 +360,9 @@ class _TimelinePostCreationScreenState
children: [
Expanded(
child: DefaultFilledButton(
onPressed: titleIsValid && contentIsValid
onPressed: titleIsValid &&
contentIsValid &&
(imageRequired ? image != null : true)
? () async {
if (formkey.currentState!
.validate()) {

View file

@ -12,6 +12,7 @@ class PostCreationTextfield extends StatelessWidget {
this.expands,
this.minLines,
this.maxLines,
this.fieldKey,
});
final TextEditingController controller;
@ -24,10 +25,12 @@ class PostCreationTextfield extends StatelessWidget {
final int? minLines;
final int? maxLines;
final String? Function(String?)? validator;
final Key? fieldKey;
@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
return TextFormField(
key: fieldKey,
validator: validator,
style: theme.textTheme.bodySmall,
controller: controller,