Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter align textfield to bottom and text from top

How do I align text from top and textfield from bottom? This is to create a sort of chat-like interface.

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Retrieve Text Input'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.end,

          children: <Widget>[
            Text(
              'Hello, How are you?\nwow',
              textAlign: TextAlign.left,
              overflow: TextOverflow.ellipsis,
              //style: new TextStyle(fontWeight: FontWeight.bold),
            ),
            TextField(
              controller: myController,
              onChanged: (text) {
                //print("First text field: $text");
              },
              onSubmitted: (text) {
                print(text);
                //myController.clear();
                myController.text = "";
              },
              decoration: new InputDecoration(
                  hintText:"Enter your response."
              ),
              focusNode: _focusNode,
              autofocus: true,
            ),
          ],
        ),
      ),
    );
  }

I've tried separating the text and textfields into containers instead but to no avail.

Is there a way to do it in flutter similar to iOS layout constraints where textfield is constrained to keyboard height and text is constrained to textfield?

like image 208
lws803 Avatar asked Jul 10 '18 07:07

lws803


People also ask

How do you change the text on top and bottom in Flutter?

start, children: [ Text("Top Text", style: TextStyle(fontWeight: FontWeight. bold, fontSize: 28)), Expanded(child: SizedBox()), Text("Bottom Text", style: TextStyle(fontSize: 18)) ], ), ); If you want, you can add a Padding Widget wrapping your Column to add internal padding to your Card Widget.

How do you align text in text field in Flutter?

How do you align hint in TextField in Flutter? textAlign : TextAlign. center is used to Align the Hint Text in Center of Text Field widget.

How do you align text Center in TextField in Flutter?

Flutter – Center Align Text in Text Widget To center align the text in a Text widget, provide textAlign property with value TextAlign. center .

How do I arrange text in Flutter?

textAlign: Flutter facilitates the alignment of text horizontally inside its parent widget's boundary using textAlign property. TextAlign comes with 7 different constants. start , end , left , right , center , justify and values . TextAlign.


1 Answers

You can insert an Expanded between the Text and TextField in your Column. This will take up as much space in between those as possible and thus push your Text up and TextField down:

Column(
  children: [
    Text(...),
    Expanded(child: Container()),
    TextField(...),
  ],
);
like image 53
creativecreatorormaybenot Avatar answered Sep 21 '22 19:09

creativecreatorormaybenot