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?
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 hint in TextField in Flutter? textAlign : TextAlign. center is used to Align the Hint Text in Center of Text Field widget.
Flutter – Center Align Text in Text Widget To center align the text in a Text widget, provide textAlign property with value TextAlign. center .
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.
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(...),
],
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With