'Changing height of container with TextField
How can I change the height of a container and automatically bring the cursor to the next line a line gets filled ( similar to WhatsApp where we type the message ) in flutter? Here is my code: Positioned( bottom: MediaQuery.of(context).size.height*0.03 , child: Container( width: MediaQuery.of(context).size.width,
),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.white,
child: IconButton(
onPressed: (){
},
icon: Icon(Icons.add),
),
),
EditableText(
expands: true,
maxLines: null,
minLines: null,
style: kTextStyle.copyWith(fontSize: 18.0),
cursorColor: Colors.white,
scrollPhysics: AlwaysScrollableScrollPhysics(),
enableSuggestions: true,
controller: _chattextcontroller,
backgroundCursorColor: Colors.grey,
focusNode: FocusNode(),
),
Expanded(
child: IconButton(
onPressed: (){
},
icon: Icon(Icons.send,
),
),
)
],
),
),
),
)
Solution 1:[1]
Use an EditableText
widget:
EditableText(
expands: true,
maxLines: null,
minLines: null,
//other required params
),
Solution 2:[2]
The following code might help you and set no. of max lines you needed.
Container(
decoration: BoxDecoration(
border: Border.all(),
),
child: const TextField(
maxLines: 5,
minLines: 1,
decoration: InputDecoration(
hintText: "Hint",
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
),
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Boken |
Solution 2 | MORE AKASH |