mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-18 18:13:46 +02:00
fix: post creation inputfields
This commit is contained in:
parent
1dc79b8d74
commit
49f0853cca
2 changed files with 11 additions and 1 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue