Aligning Text in Card under Column and Row - android-studio

I want to achieve the UI like this. The Title, SubTitle and BottomText are all neatly aligned.
What I have gotten so far by myself is this, it is a Card containing all the widgets. How to I do so that the Subtitle and the BottomText aligns with the Title?
Here is my code:
return ListView(
padding: EdgeInsets.all(8.0),
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: <Widget>[
Container(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0)
),
color: Colors.white,
elevation: 10,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(20.0, 8.0, 8.0, 8.0),
child: Text('Title', style: TextStyle(fontWeight: FontWeight.bold),),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
children: <Widget>[
Text('Text2'),
Text('Text2'),
],
),
Column(
children: <Widget>[
Text('Text2'),
Text('Text2'),
],
),
Column(
children: <Widget>[
Text('Text2'),
Text('Text2'),
],
)
],
),
Container(
padding: EdgeInsets.all(8.0),
color: Colors.orange,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Text2'),
Text('Text2'),
Checkbox(value: false,)
],
),
)
],
),
),
)
],
);

Just a little improvement, and you will achieve want you want to achieve.
Final solution:
return ListView(
padding: EdgeInsets.all(8.0),
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: <Widget>[
Container(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft: Radius.circular(40.0), topRight: Radius.circular(40.0), bottomLeft: Radius.circular(15.0), bottomRight: Radius.circular(15.0))
),
color: Colors.white,
elevation: 10,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(20.0, 30.0, 8.0, 8.0),
child: Text(
'Title',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Container(
padding: EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
children: <Widget>[
Text('Text2'),
Text('Text2'),
],
),
Column(
children: <Widget>[
Text('Text2'),
Text('Text2'),
],
),
Column(
children: <Widget>[
Text('Text2'),
Text('Text2'),
],
)
])),
Container(
padding:
EdgeInsets.symmetric(vertical: 8.0, horizontal: 20.0),
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(15.0)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Text2'),
Text('Text2'),
Checkbox(
value: false,
)
],
),
)
],
),
),
)
],
);
And here how your result will look like:

Related

How to get indent between image and appbar in Flutter app?

Here is the code without body of the widget:
Column(
children: [
Material(
elevation: 0,
child: Image.asset(
i.first,
fit: BoxFit.fitWidth,
),
),
SizedBox(
width: 130,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Text(
i.last
),
),
),
),
],
Need to add space between appbar and image.
How can i achieve additional space between image and appbar widgets?
You can use Padding Widget:
body: Padding(
padding: const EdgeInsets.all(8.0),
child: GridView.count(
crossAxisCount: 2,
children: [
...myImageAndCaption.map(
(i) => Column(
mainAxisSize: MainAxisSize.min,
children: [
Material(
elevation: 0,
child: Image.asset(
i.first,
fit: BoxFit.fitWidth,
height: 150,
width: 150,
),
),
SizedBox(
width: 130,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Text(
i.last,
style: const TextStyle(
fontSize: 22,
letterSpacing: 1.0,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
),
),
],
),
),
],
),
),

"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'),
),
],
)
],
)
],
),

Is it possible to put A Column in a Row in Flutter?

I tried putting a column in a row. But it does not work.
Then I tried putting the row and column in the same safe area using different child properties. It does not work.
The column is supposed to be in the middle of the row.
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.teal,
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: 100.0,
width: 100.0,
color: Colors.yellow,
child: Text('Container 1'),
),
Container(
height: 100.0,
width: 100.0,
color: Colors.green,
child: Text('Container 1'),
),
Container(
width: double.infinity,
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
height: 100.0,
color: Colors.red,
child: Text('Container 1'),
),
Container(
height: 100.0,
color: Colors.blue,
child: Text('Container 1'),
),
],
),
),
),
);
}
}
The error message is "BoxConstraints forces an infinite width."
Try expanded widget with flex attribute, you can put the column in a row:
Container(
width: 300,
height: 100,
child: Row(
children: <Widget>[
Expanded(flex: 1,
child: Container(
color: Colors.red,
width: double.infinity,
height: double.infinity,
),
),
Expanded(flex: 2,
child: Column(
children: <Widget>[
Expanded(flex:1,
child: Container(
color: Colors.yellow,
width: double.infinity,
height: double.infinity,
),
),
Expanded(flex:1,
child: Container(
color: Colors.blue,
width: double.infinity,
height: double.infinity,
),
),
],
),
),
Expanded(flex: 1,
child: Container(
color: Colors.green,
width: double.infinity,
height: double.infinity,
),
),
],
),
),
also, you can place column using a container
body: SafeArea(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 100.0,
color: Colors.red,
),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 100.0,
height: 100.0,
color: Colors.yellow,
),
Container(
width: 100.0,
height: 100.0,
color: Colors.green,
),
],
),
),
Container(
width: 100.0,
color: Colors.blue,
),
],
),
),

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 How to using text field inside ListTile?

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(),
),
),

Resources