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

How to create a multiline Flutter textField? #303

Open
SimonLab opened this issue Feb 8, 2023 · 6 comments
Open

How to create a multiline Flutter textField? #303

SimonLab opened this issue Feb 8, 2023 · 6 comments
Assignees
Labels
flutter Flutter related issues priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T1h Time Estimate 1 Hour UI

Comments

@SimonLab
Copy link
Member

SimonLab commented Feb 8, 2023

image

The text field can contains multiple lines, however at the moment the content is centered.
I'm going to look at the Flutter layout and find a solution to make sure the text start at the top of the widget.
I'm not sure if there is an option on the text field widget or if it's a column or expands widgets related issue

@SimonLab SimonLab added UI priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T1h Time Estimate 1 Hour labels Feb 8, 2023
@SimonLab SimonLab self-assigned this Feb 8, 2023
@nelsonic
Copy link
Member

nelsonic commented Feb 8, 2023

@SimonLab thanks for capturing this quest. 👌

@SimonLab SimonLab added the flutter Flutter related issues label Feb 8, 2023
@SimonLab SimonLab moved this to 🏗 In progress in dwyl app kanban Feb 8, 2023
@SimonLab SimonLab added the in-progress An issue or pull request that is being worked on by the assigned person label Feb 8, 2023
@SimonLab
Copy link
Member Author

SimonLab commented Feb 8, 2023

    return MaterialApp(
        title: 'App',
        theme: ThemeData(
          primarySwatch: Colors.teal,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: const Text('DWYL'),
            centerTitle: true,
          ),
          body: const TextField(
            decoration: InputDecoration(
                hintText: 'Capture what is on your mind...',
                border: OutlineInputBorder()),
            maxLines: null,
            expands: true,
            textAlignVertical: TextAlignVertical.top,
          ),
        ));

The TextField widget height is set by defining masLines to null and expands to `true
image
image

Then we set the textAlignVertical option with TextAlignVertica.top constant
image

image

See TextField Widget documentation

@SimonLab
Copy link
Member Author

SimonLab commented Feb 8, 2023

Note that now the field is multiline the submit button on the keyboard is replaced by the enter key to create new line.
You can configure which type of keyboard you want to display for the text field with the option keyboardType, for example keyboardType: TextInputType.multiline (the default keyboard for multiline).

Other values:
image
see https://api.flutter.dev/flutter/services/TextInputType-class.html

If you use the text value the submit key is displayed however now you can not create new lines.
We'll need to add the save button on the screen to save the item.

@SimonLab
Copy link
Member Author

SimonLab commented Feb 8, 2023

I'm going to look at changing dynamically some of the options. Display the textField as a one line text the on focus expands the text field to takes all the screen and hide other items on the page.

We can try this UI, however I think we should try also to have the list of items and input text split into two views.

@SimonLab
Copy link
Member Author

SimonLab commented Feb 8, 2023

Using stateful widget for the text field as I want the value for maxLines and expands to be dynamic.

First display the text field on one line:
image

When the text field is tapped, change the maxLines and expands values to extends the text field. I've also added a save button:
image

Clicking the button change the text file to be on one line again.

The onTap callback is not the best way to expand the text field widget, I'm looking now instead on how to detect focus on a widget

@SimonLab SimonLab removed the in-progress An issue or pull request that is being worked on by the assigned person label Feb 14, 2023
@LuchoTurtle
Copy link
Member

@SimonLab isn't this issue been already completed and merged? #302
👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flutter Flutter related issues priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T1h Time Estimate 1 Hour UI
Projects
Status: 🏗 In progress
Development

No branches or pull requests

3 participants