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

View file

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