Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput is not recorded #3

Closed
Mateis opened this issue Oct 23, 2020 · 7 comments
Closed

TextInput is not recorded #3

Mateis opened this issue Oct 23, 2020 · 7 comments

Comments

@Mateis
Copy link

Mateis commented Oct 23, 2020

Issue:
I can type words in the input form, yet after pressing space or enter, the words dissapear and no tag is renderd. Also, tags are not showing up at print in console.

Expected:

  • tags to show up after space
  • onTag to show a print in console when a tags is added

Debug console:

W/IInputConnectionWrapper( 5213): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5213): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5213): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5213): endBatchEdit on inactive InputConnection

My code:

class _PostFormState extends State<PostForm> {

  TextEditingController title = TextEditingController();
  List<String> tags;

  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Form(
                key: _formKey,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    TextFormField(
                          controller: title,
                          decoration: InputDecoration(hintText: 'Title'),
                          maxLength: 140,
                          validator: (value) {
                            if (value.isEmpty) {
                              return 'Please enter a title';
                            } else {
                              return null;
                            }
                          }),
                    SizedBox(height: 16,),
                    TextFieldTags(
                      onTag: (tag) {
                        tags.add(tag);
                        print(tags);
                      },
                      // onDelete: (tag) {
                      //   tags.remove(tag);
                      // },
                    ),
                    RaisedButton.icon(
                        onPressed: () {
                           // Validate returns true if the form is valid, otherwise false.
                            if (_formKey.currentState.validate()) {
                              // Provide userfeedback while processing
                              Scaffold
                                  .of(context)
                                  .showSnackBar(SnackBar(content: Text('Processing Data')));

                              // Post to firebase
                              Future result = widget.db.post(widget.audio, title, tags);

                                result.then((user) => Navigator.of(context)
                                    .pushReplacementNamed(homeRoute, arguments: 2)).catchError((e) => throw 'error in posting' + e);
                              }
                            },                         
                        label: Text('Post'),
                        icon: Icon(Icons.post_add),
                      ),
                  ],
                ),
              );
  }
}

My environment:

[√] Flutter (Channel beta, 1.22.0-12.1.pre, on Microsoft Windows [Version 10.0.18363.1139])
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.50.1)
[√] Connected device (1 available)

I ran in an emulator in debug mode

@eyoeldefare
Copy link
Owner

I will look into this tomorrow.

@eyoeldefare
Copy link
Owner

eyoeldefare commented Oct 23, 2020

So the reason you're getting this error is because you're not calling textFieldStyler and tagsStyler properties inside TextFieldTags Widget. But its also my failt for not making those manditory. So I will fix that tomorrow. But if you want to fix it right now, you can just do this:

TextFieldTags(textFieldStyler: TextFieldStyler(), tagsStyler: TagsStyler(),);

@eyoeldefare
Copy link
Owner

Solved

@Mateis
Copy link
Author

Mateis commented Oct 25, 2020

Great thank you. Yes, I considered them optional and a default would apply if not set.

@Mateis
Copy link
Author

Mateis commented Oct 25, 2020

I tried the solution, yet it is still not functional.

I can type things, yet when I hit space/enter it just removes the text and puts back the placeholder.

How I implemented it now:

TextFieldTags(
  textFieldStyler: TextFieldStyler(), 
  tagsStyler: TagsStyler(),
  onTag: (tag) {
    tags.add(tag);
    print(tag);
   },
  onDelete: (tag) {
    tags.remove(tag);
  },
)
W/IInputConnectionWrapper( 5983): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5983): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5983): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5983): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5983): endBatchEdit on inactive InputConnection
E/SpannableStringBuilder( 5983): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
E/SpannableStringBuilder( 5983): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

Maybe because I use it inside a Form() widget with validation, could that be related?

@eyoeldefare
Copy link
Owner

I tried the solution, yet it is still not functional.

I can type things, yet when I hit space/enter it just removes the text and puts back the placeholder.

How I implemented it now:

TextFieldTags(
  textFieldStyler: TextFieldStyler(), 
  tagsStyler: TagsStyler(),
  onTag: (tag) {
    tags.add(tag);
    print(tag);
   },
  onDelete: (tag) {
    tags.remove(tag);
  },
)
W/IInputConnectionWrapper( 5983): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5983): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5983): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5983): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5983): endBatchEdit on inactive InputConnection
E/SpannableStringBuilder( 5983): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
E/SpannableStringBuilder( 5983): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

Maybe because I use it inside a Form() widget with validation, could that be related?

This is actually a bug from your code. You need to initialize your properties. List<String> tags; needs to be List<String> tags = [];. You can't add stuff to a null property.

@Mateis
Copy link
Author

Mateis commented Oct 25, 2020

Perfect. Works now. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants