Negative Content Padding in Container - flutter

I have a list with an Container. With a Content Padding of 0 it´s look like this:
but I want the List Tile (the white writing) in the middle of the box.
Here is the part of my Code where the Magic is done:
return Card(
color: Color.fromRGBO(25, 29, 30, 100),
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
child: Container(
height: 70,
padding: EdgeInsets.fromLTRB(15, 20, 20, 15),
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.red,
),
child: ListTile(
contentPadding: EdgeInsets.symmetric(vertical: 0),
leading: Checkbox(
side: const BorderSide(
color: Colors.white
),
Thanks for help in advance

use title in your ListTile like this
ListTile(
contentPadding: EdgeInsets.symmetric(vertical: 0),
leading: Checkbox(
side: const BorderSide(
color: Colors.white
),
),
title: Text('Your text'),
)

Nevermind.
I removed the container and changed the code to this:
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
color: Colors.red,
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
child: ListTile(...
It solved the problem with the container and positioned the ListTile in the middle

Related

Flutter Card and Container design

I wanted to achieve this:
But I end up getting this (ignore the color):
How can I shape the border of the colored border side, I keep getting this weird error (or at least I have never encounter one), I shape the topLeft and bottomLeft border and it pops up A borderRadius can only be given for a uniform Border. What am I doing wrong here? I have placed a Container inside a Card widget, I tried the other way around, but not the results I expected. I now have what I need, I just need to round the topLeft and bottomLeft corner of the Container (Or maybe something else) to achieve the goal from the first picture with the blue colour.
Here is the code:
Container(
height: 98.0,
width: double.infinity,
child: Card(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0),
),
shadowColor: Color.fromRGBO(0, 0, 0, 0.6),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), //this is causing the error, when I remove it, I get the card like on picture 2 with the red line
border: Border(
left: BorderSide(
color: Colors.red,
width: 3.0,
style: BorderStyle.solid),
),
),
child: Row(
// some content here
],
),
),
),
),
Thanks in advance for the help!
please try with this
Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
color: Colors.green,
elevation: 16,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Wrap(
children: [
Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(10),
topRight: Radius.circular(10))),
margin: EdgeInsets.only(left: 10),
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Dr. Alok Verma",
style: TextStyle(fontSize: 24),
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text("Date: 14-06-2021",
style: TextStyle(fontSize: 24))),
Expanded(
child: FlatButton(
onPressed: () {},
child: Container(
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(5)),
padding: EdgeInsets.all(8),
child: Text("Completed",
style: TextStyle(fontSize: 24)))))
],
),
Text("Time: 10:20", style: TextStyle(fontSize: 24)),
SizedBox(
height: 20,
),
Text("Aastha Hospital",
style: TextStyle(
fontSize: 24, fontWeight: FontWeight.bold)),
Text("Some address", style: TextStyle(fontSize: 18)),
],
),
)
],
),
),
)
image:

Flutter ExpansionTile title vertical padding

How can I remove vertical padding in leading Widget in ExpansionTile so it looks like ListTile below it?
Here is my code:
Container(
decoration: BoxDecoration(
border: Border.all(color: Color.fromRGBO(200, 200, 200, 1), width: 2),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: ListTileTheme(
contentPadding: EdgeInsets.zero,
dense: true,
child: ExpansionTile(
childrenPadding: EdgeInsets.zero,
tilePadding: EdgeInsets.zero,
title: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text(Constants.texts.chooseFromList,
style: Constants.textStyles.lightGreyMediumSize),
),
children: [
Text('One'),
Text('Two'),
Text('Three'),
],
trailing: Image.asset(
'assets/icons/snn_app_ubytovanie_filter_open_button_merged_idle_crop.png',
)),
),
)
Code for ListTile under it is following:
Container(
decoration: BoxDecoration(
border: Border.all(
color: Color.fromRGBO(200, 200, 200, 1), width: 2),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: ListTileTheme(
contentPadding: EdgeInsets.zero,
dense: true,
child: ListTile(
title: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text("Here it works!",
style: Constants.textStyles.lightGreyMediumSize),
),
trailing: Image.asset(
'assets/icons/snn_app_ubytovanie_filter_open_button_merged_idle_crop.png',
),
),
),
)
I alredy copy&paste and refactor source code for ExpansionTile from flutter repo but I can't seem to figure out what is causing the padding. Please any advice is much appreciated.
Ok so I have found that what is cousing a gap is actuly transparent border in original ExpansionTile source code here:
Container(
decoration: BoxDecoration(
color: _backgroundColor.value ?? Colors.transparent,
border: Border(
top: BorderSide(color: borderSideColor),
bottom: BorderSide(color: borderSideColor),
),
),
Although it derives it's color from backgroundColor parameter, only work-around I found to solve my issue was to edit source code for original ExpansionTile and delete BoxDecoration. Hope this helps anyone with same issue.

How do i set the position of picture/button/text to be responsive for other device?

I try to set the position of picture/button/text by define the number but when my code run to others device my UI is not the same as runing on my device. This is the picture that show the result on my device and othe devide.
my device
others device
So, I try to use this code to make my code to be responsive.
Container(
child: Positioned(
left: MediaQuery.of(context).size.width*0.4,
top: MediaQuery.of(context).size.height*0.28,
width: 100,
height: 100,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/LG5.png"))),
))),
And for setting the position of button and login TextFiled I use this code
Container(
margin: const EdgeInsets.only(left: 80.0, right: 80.0, top: 300),
child: Column(
children: <Widget>[
TextField(
obscureText: true,
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
borderSide:
BorderSide(width: 3, color: Colors.indigo[700]),
),
labelText: 'Password',
),
),
TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
borderSide:
BorderSide(width: 3, color: Colors.indigo[700]),
),
labelText: 'Username',
),
),
Container(
width: 300,
margin: const EdgeInsets.only(top: 40),
child: RaisedButton(
child: Text('Login',
style: TextStyle(color: Colors.white, fontSize: 20)),
color: Colors.indigo[700],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeScreen()));
}),
)
for the above code I use this code to set position of TextFiled
margin: const EdgeInsets.only(left: 80.0, right: 80.0, top: 300)
for button for login is
margin: const EdgeInsets.only(top: 40)
As you see, i define the number for the position and i try to use this code and assign to the left,right,top of "EdgeInsets.only" but it doesn't work.
MediaQuery.of(context).size.width
MediaQuery.of(context).size.height
So, how can i define the value of left,right,top with "EdgeInsets.only" and no need to fix the number and it will reponsive to other device?
Or, you can suggest me to do another way that more proper than this way because i'm not sure that i do the right way. I just learn Flutter.
Thank you.
Instead of using absolute values like 20, 30 or whatsoever, try to use %. This way your UI will be responsive

cardview in flutter layout

I want the code to design a cardview in flutter with all properties:
See
https://api.flutter.dev/flutter/material/Card-class.html
https://api.flutter.dev/flutter/widgets/Row-class.html
https://api.flutter.dev/flutter/material/CircleAvatar-class.html
Then post code for what you have attempted if you still have questions.
Padding(
padding: EdgeInsets.all(20),
child: Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
elevation: 5,
color: Colors.white,
child: Row(children: [
Padding(
padding: EdgeInsets.all(10),
child: Card(
shape: CircleBorder(),
elevation: 10,
color: Colors.white,
child: Icon(Icons.account_circle, color: Colors.black, size: 100)),
),
Padding(
padding: EdgeInsets.all(10),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
elevation: 10,
color: Colors.green[400],
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text('#anonymous',
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold)),
)),
)
])),
)
You can modify and add relevant fields as your requirement !
return Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
color: Colors.white,
child: Row(children: [
SizedBox(
width: 30,
),
Card(
shape: CircleBorder(),
color: Colors.white,
child: Icon(Icons.account_circle, color: Colors.black, size: 50)),
SizedBox(
width: 30,
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
color: Colors.green[800],
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text('#anonymous',
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold)),
))
]));

Add border to a Container with borderRadius in Flutter

Container(
child: Text(
'This is a Container',
textScaleFactor: 2,
style: TextStyle(color: Colors.black),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
border: Border(
left: BorderSide(
color: Colors.green,
width: 3,
),
),
),
height: 50,
),
This is supposed to show a rounded-edged container with a green left border 3px wide, and the child Text "This is a Container". However, it just shows a rounded-edged container with an invisible child and an invisible left border.
When I take out the borderRadius object, the child Text and the green left border is visible, but introducing it hides the left border and child Text again.
The major problem seems to be the custom left border, because using border: Border.all(width: 0) and borderRadius: BorderRadius.circular(10) makes the edges rounded as needed and also shows the child. But now I cant apply the green left border which is quite important in this particular setup.
So is there something I'm doing wrong, or is this a bug in flutter, or is it just something that is not allowed?
Thank you in advance.
Edit: The image below is the end result. The colors don't matter
It's not possible to add border: and borderRadius: at the same time, you'll get this error:
A borderRadius can only be given for uniform borders.
You can achieve what you want using the borderRadius: and a boxShadow: instead of border: like this:
boxShadow: [
BoxShadow(color: Colors.green, spreadRadius: 3)
]
Your sample code would be like this:
Container(
child: Text(
'This is a Container',
textScaleFactor: 2,
style: TextStyle(color: Colors.black),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(color: Colors.green, spreadRadius: 3),
],
),
height: 50,
),
Edit: To achieve the example you now provided, you could do this:
Container(
padding: EdgeInsets.only(left: 12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.green,
),
height: 50,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10.0),
bottomRight: Radius.circular(10.0)),
color: Colors.white,
),
child: Text(
'This is a Container',
textScaleFactor: 2,
style: TextStyle(color: Colors.black),
),
),
),
Another solution:
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white,
),
height: 50,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
width: 12.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
bottomLeft: Radius.circular(10.0)),
color: Colors.green,
),
),
Text(
'This is a Container',
textScaleFactor: 2,
style: TextStyle(color: Colors.black),
)
],
),
),
There is an answer here
Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFFF05A22),
style: BorderStyle.solid,
width: 1.0,
),
color: Colors.transparent,
borderRadius: BorderRadius.circular(30.0),
),
),
This might be so late but also it might be useful for others.
You can wrap your Container inside a ClipRRect, give the ClipRRect the radius and give the Container the border!
Example:
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
child: Container(
height: 100,
width: double.maxFinite,
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
border: Border(
left: BorderSide(width: 8.0, color: Colors.green),
),
),
),
),
This should do the UI you lastly posted.
If you want to achieve borderRadius you could also use a PhysicalModel, but you'll have to provide colour. You also can have a shadow for your widget.
PhysicalModel(
color: Colors.red,
elevation: 5,
shadowColor: Colors.blue,
borderRadius: BorderRadius.circular(20),
child: SizedBox(width: 75, height: 75),
)
I think an easier way inspired by #pablo 's answer would be to just make a boxShadow with and offset but without any blur.
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(
top: Radius.circular(10),
),
boxShadow: [
// to make elevation
BoxShadow(
color: Colors.black45,
offset: Offset(2, 2),
blurRadius: 4,
),
// to make the coloured border
BoxShadow(
color: Colors.blue,
offset: Offset(0, 4),
),
],
),
The decoration above will give us an elevated box which has a blue border in the bottom.
Another benefit of this approcah is that you can use it with
borderRadius: BorderRadius.circular(num)
Which means you can have a container with all rounded sides + a colored border.
Please note that the coloured border comes under the original shadow. This is done to prevent the elevation color from darkening the border.
I archieve do a Inkwell (that simulate a button) circular with an icon inside :
InkWell(
onTap: (){},
child: Container(
width: 50,
height: 50,
decoration: ShapeDecoration(
shape: CircleBorder(), //here we set the circular figure
color: Colors.red
),
child: Center(
child: Icon(
Icons.email,
size: 30,
color: Colors.white,
)
),
)
)
link example of result: https://images.vexels.com/media/users/3/140138/isolated/preview/88e50689fa3280c748d000aaf0bad480-icono-de-ronda-de-correo-electronico-1.png
////Hope this will work for you,Thanks
import 'package:flutter/material.dart';
class System extends StatefulWidget {
const System({Key? key}) : super(key: key);
#override
_SystemState createState() => _SystemState();
}
class _SystemState extends State<System> {
#override
Widget build(BuildContext context) {
return Scaffold(
body:Padding(
padding: const EdgeInsets.only(top:80.0),
child: Column(
children: [
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
height: 100,
width: double.maxFinite,
padding: const EdgeInsets.all(16.0),
decoration: const BoxDecoration(
color: Color(0xffF6EBEC),
border: Border(
bottom: BorderSide(width: 8.0, color: Color(0xffA24949)),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircleAvatar(
backgroundColor: Color(0xffA24949),
child: Icon(Icons.close,
color: Color(0xffF6EBEC), size: 40),
),
const SizedBox(width: 10),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text("Invalid",
style: TextStyle(color: Color(0xffA24949), fontSize: 18)),
SizedBox(
width: 243,
child: Text("Details do not match the issuer records",overflow: TextOverflow.ellipsis,maxLines: 1,))
])
],
),
),
),
),
),
SizedBox(height: 20,),
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
height: 100,
width: double.maxFinite,
padding: const EdgeInsets.all(16.0),
decoration: const BoxDecoration(
color: Color(0xFFE9F6EB),
border: Border(
bottom: BorderSide(width: 8.0, color: Color(0xFF69A258),),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircleAvatar(
backgroundColor: Color(0xFF69A258),
child: Icon(Icons.check_rounded,
color: Color(0xFFE9F6EB), size: 40),
),
const SizedBox(width: 15),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text("Valid",
style: TextStyle(color: Color(0xFF69A258), fontSize: 18)),
Text("Document successfully validated.")
])
]),
),
),
),
),
],
),
),
);
}
}