Flutter How to using text field inside ListTile? - layout

I wanna implement a ListTile which in the tailing is a textfield, this is something like iOS static tableview, so that users can click it and directly edit text.
How to do this in Flutter anyway?

For the future people may also have this trouble, here is the solution:
new ListTile(
title: Text('签名'),
trailing: new Container(
width: 150.0,
child: new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new Expanded(
flex: 3,
child: new TextField(
textAlign: TextAlign.end,
decoration:
new InputDecoration.collapsed(hintText: '$userAddr'),
),
),
new Expanded(
child: new IconButton(
icon: new Icon(Icons.chevron_right),
color: Colors.black26,
onPressed: () {},
),
)
],
),
),
),
Always using a Expand for textfiled.

Right now, on V1.12 of flutter, you can put a Row in the title and populate it
ListTile(
title: Row(
children: <Widget>[
Expanded(
child: Text('签名')
),
Expanded(
child: TextField(
// your TextField's Content
),
),
],
),
trailing: IconButton(
icon: new Icon(Icons.chevron_right),
color: Colors.black26,
onPressed: () {},
)
),

Try the following code:
ListTile(
title: Text("Price"),
trailing: SizedBox(
width: MediaQuery.of(context).size.width * 0.2,
child: TextField(),
),
),

Related

"RenderBox was not laid out" text field error in flutter

I'm trying to put a textfield, the error does not appear, but I think I'm getting a logical error.
I guess sizing is required. But I couldn't understand where to specify.
And the screen is blank.
I don't know if I could explain it properly because my English is not good.
child: Row(
children: <Widget>[
Column(
children: <Widget>[
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your email',
),
validator: (String? value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: null,
child: Text('Submit'),
),
),
],
),
Column(
children: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
backgroundColor: Colors.blueAccent,
),
onPressed: null,
child: const Text('Button'),
),
Row(
children: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
backgroundColor: Colors.blueAccent,
),
onPressed: null,
child: const Text('Button2'),
),
],
)
],
)
],
),
),`
Somehow you have to tell Flutter how should it size the two columns in the row. One of the possible solutions is to wrap the first column in an Expanded widget. As a result the second column will be drawn, its size is determined by the text sizes of Button and Button2). And then the first column will occupy all the remaining space, that's what Expanded means. Code:
Row(
children: <Widget>[
Expanded( // <--- this is added, the rest is unchanged
child: Column(
children: <Widget>[
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your email',
),
validator: (String? value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: null,
child: Text('Submit'),
),
),
],
),
),
Column(
children: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
backgroundColor: Colors.blueAccent,
),
onPressed: null,
child: const Text('Button'),
),
Row(
children: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
backgroundColor: Colors.blueAccent,
),
onPressed: null,
child: const Text('Button2'),
),
],
)
],
)
],
),

Anroid-layout How can make custom button like this?

those three things are clickable buttons, I don't know how to make it....
enter image description here
return Scaffold(
backgroundColor: Colors.grey[200],
body: Padding(
padding: const EdgeInsets.all(28.0),
child: Column(
children: [
Card(
child: new InkWell(
onTap: () {},
child: Container(
child: ListTile(
title: Text(
"Bignners Level Lessons",
),
subtitle: Text("write your text"),
),
height: 100.0,
),
),
),
Card(
child: new InkWell(
onTap: () {},
child: Container(
child: ListTile(
title: Text(
"Bignners Level Lessons",
),
subtitle: Text("write your text"),
),
height: 100.0,
),
),
),
Card(
child: new InkWell(
onTap: () {},
child: Container(
child: ListTile(
title: Text(
"Bignners Level Lessons",
),
subtitle: Text("write your text"),
),
height: 100.0,
),
),
),
],
),
),
);
}
}

inverse a List view inside a drawer

I want to know how to make a list view inside a drawer shows from the other side, and I'm confused why it gave me the default apperance like this:
drawer: Drawer(
child: Container(
alignment: Alignment.centerLeft,
child: ListView(
children: <Widget>[
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.home),
label: Text('Home')),
),
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.favorite),
label: Text('Favorite')),
),
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.share),
label: Text('Share_app')),
),
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.info),
label: Text('About Us')),
),
ListTile(
trailing: FlatButton.icon(
onPressed: _onClicked,
icon: Icon(Icons.settings),
label: Text('Settings')),
),
],
),
)));
}
}
thank you for your help
Is there a reason why you want to put your Icon in the trailing position, and also put a label to it? If you want to simply display a ListView of ListTile children, you can simply do this:
ListView(
children: [
ListTile(
leading: Icon(Icons.home),
title: Text('Home'),
onTap: // onTap callback
),
...
],
),
Or am I misunderstanding the question?

Put stretched rows inside a column in flutter app

I am building a flutter app layout which requires to have some widgets to be put horizontally together in a row ,
some Rows should be put together in a column,
i tried to put the rows inside the column directly but it didn't work,
that's the code used:
child: new SingleChildScrollView(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center ,
crossAxisAlignment: CrossAxisAlignment.center ,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(0.0),
child: new Container(
margin: EdgeInsets.all(20.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
//the problem shows up here
],
),
),
),
//card to hold the addition form
Padding(
padding: const EdgeInsets.all(0.0),
child: new Container(
margin: EdgeInsets.all(20.0),
child:new Card(
color:Colors.white,
margin: EdgeInsets.all(1.0),
shape: new RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
...
],
),
),
decoration: new BoxDecoration(boxShadow: [
new BoxShadow(
color: Colors.black12,
blurRadius: 2.0,
offset: new Offset(0.0, 0.0),
),
]),
),
),
],
),
),
),
update:
that's exactly what i want to make
a main column that contain rows and columns to build this view
putting the card inside the column is working fine but nothing work when i add row inside the column
i also updated the code and hope it's completely clear now
the problem was in the alignment
this worked fine
'''
child: new SingleChildScrollView(
// the main content container
child: new Column(
children: [
Padding(
padding: const EdgeInsets.all(1.0),
child: new Container(
margin: const EdgeInsets.only(
left: 20.0, top: 20.0, right: 20.0, bottom: 0.0),
//Current date and time container
child: new Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
],
),
),
),
//card to hold the addition form
Padding(
padding: const EdgeInsets.all(1.0),
child: new Container(
margin: EdgeInsets.all(20.0),
//the addition shadow handler
child: new Card(
color: Colors.white,
margin: EdgeInsets.all(1.0),
shape: new RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0)),
//the addition form container
child: new Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
//Type and amount container
Padding(
padding: EdgeInsets.all(12.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
//Amount container
new Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
],
),
//Type container
new Column(
children: <Widget>[
],
),
],
),
),
],
),
),
decoration: new BoxDecoration(boxShadow: [
new BoxShadow(
color: Colors.black12,
blurRadius: 2.0,
offset: new Offset(0.0, 0.0),
),
]),
),
),
],
),
),
'''

Flutter text display issue

Am writing a very basic app that just displays numbers on the screen and you can increase and decrease the value of this number with some buttons.
Works fine, except for some reason the text display often goes nuts. I'll show you what I mean:
The above text is trying to display a value of 20, but it is struggling for some reason, as you can see.
This only appears to be happening with double-digit or higher values. My code:
class _SinglePlayerModeParentState extends State<SinglePlayerMode> {
#override
void initState() {
super.initState();
SystemChrome.setEnabledSystemUIOverlays([]);
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,]);
}
#override
Widget build(BuildContext context) {
Widget numberDisplay = GestureDetector(
onTap: () {
print("GestureDetector");
_incrementBy1();
},
child: Center(child: Text(_numberValue.toString(),
style: TextStyle(
fontSize: 200.0,
color: Colors.white,
),
),
),
);
This code was already displaying these text issues before I rearranged the code to include the following as well:
Widget buttonRow() {
return Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 40.0, right: 20.0),
child: FloatingActionButton(
heroTag: null,
onPressed: _numberValueMinus5,
child: Text('-5'),
),
),
Padding(
padding: EdgeInsets.only(left: 20.0, right: 40.0),
child: FloatingActionButton(
heroTag: null,
onPressed: _numberValueMinus1,
child: Text('-1'),
),
),
],
),
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 40.0, right: 20.0),
child: FloatingActionButton(
heroTag: null,
onPressed: _numberValuePlus1,
child: Text('+1'),
),
),
Padding(
padding: EdgeInsets.only(left: 20.0, right: 40.0),
child: FloatingActionButton(
heroTag: null,
onPressed: _numberValuePlus5,
child: Text('+5'),
),
),
],
),
],
);
}
return MaterialApp(
title: 'Bean Counter',
home: Scaffold(
backgroundColor: Colors.blueAccent,
body: Column(
children: [
Padding(
padding: EdgeInsets.only(top: 90.0, bottom: 40.0),
child: numberDisplay,
),
buttonRow(),
],
),
),
);
}
Not sure what I can do differently here, it's just text!
Any thoughts?
Edit: Testing the FittedBox solution.
#override
Widget build(BuildContext context) {
Widget numberDisplay = GestureDetector(
onTap: () {
print("GestureDetector");
_incrementBy1();
},
child: Center(
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(_numberValue.toString(),
style: TextStyle(
fontSize: 200.0,
color: Colors.white,
),
),
),
),
);
}
Results: this is trying to display the number 30:
As you can see, it still isn't displaying properly. I also tried BoxFit.contain, same issue. Information obtained from this reference: https://docs.flutter.io/flutter/painting/BoxFit-class.html
Any other ideas guys? Or did I implement FittedBox incorrectly?
Edit: Tried with AutoSizeText, as recommended below. Code:
#override
Widget build(BuildContext context) {
Widget scoreText = GestureDetector(
onTap: () {
print("GestureDetector");
_incrementBy1();
},
child: Center(
child: AutoSizeText(_numberValue.toString(),
style: TextStyle(
fontSize: 200.0,
color: Colors.white,
),
),
),
);
Results:
Argh! Displaying text on a clear screen. Level: difficult.

Resources