Flutter how to make the Container expand full height - flutter

I want to expand the background color of the Container to take the full height.
I already tried to set the height to double infinite and that just gets rid of my Two Text Widgets Title and Lemon Chicken. This is the code its inside a Scalfold widget this part its only the body.
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 36),
child: GestureDetector(
onTap: () => print('Add Image'),
child: Icon(
Icons.add_a_photo,
size: 70,
color: Theme.of(context).primaryColor,
),
),
),
Container(
width: double.infinity,
margin: EdgeInsets.symmetric(horizontal: 24),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24.0),
topRight: Radius.circular(24.0),
),
color: Colors.pink,
),
child: Form(
child: Padding(
padding: const EdgeInsets.all(12.0),
child: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Title',
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold),
),
Text(
'Lemon Chicken',
style:
TextStyle(color: Theme.of(context).primaryColor),
)
],
),
),
),
),
),
],
),
),
This is the Image of my app.
I just want to expand the Widget has the pink background color

you can use mediaquery to find device's height and set that as container's height
Container(
height: MediaQuery.of(context).size.height,
width: double.infinity,
margin: EdgeInsets.symmetric(horizontal: 24),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24.0),
topRight: Radius.circular(24.0),
),
color: Colors.pink,
),
or as you did you can use double.infinity
Container(
height:double.infinity,
result:

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:

Splash color is not visible while I am using it in my Custom ModalBottomSheet

I am not getting splash effect when my Inkwell is inside showModalBottomsheet while it is customized, I wanted the rounded corners, so I hide the background color to transparent, when the background color is in white, the splash effect works fine. I tried playing with Alpha and Opacity properties, but no luck there.
questionEditAndDelete(BuildContext context) {
return showModalBottomSheet(
context: context,
elevation: 0,
backgroundColor: Colors.transparent,
builder: (context) {
return Container(
height: MediaQuery.of(context).size.height * 0.15,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(25), topLeft: Radius.circular(25)),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Padding(
padding: const EdgeInsets.only(bottom:20.0),
child: Divider(
indent: 110,
endIndent: 110,
thickness: 4,
color: Colors.grey,
),
),
InkWell(
onTap: (){},
splashColor: Colors.grey,
borderRadius: BorderRadius.all(Radius.circular(15)),
child: Container(
height: MediaQuery.of(context).size.height*0.05,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal:4.0),
child: Icon(EvaIcons.editOutline, size: 26,),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal:2.0),
child: Text('Edit', style: TextStyle(fontSize: 18),),
)
],
),
),
),
InkWell(
onTap: (){},
splashColor: Colors.grey,
borderRadius: BorderRadius.all(Radius.circular(15)),
child: Container(
height: MediaQuery.of(context).size.height*0.05,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal:4.0),
child: Icon(Icons.delete_outline_outlined, size: 26,),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal:2.0),
child: Text('Delete', style: TextStyle(fontSize: 18),),
)
],
),
),
),
]),
);
});
}```
Yes you are right so available alternate options are
Replace InkWell with Gesture Detector
Remove splash color of InkWell or set splash color to Colors.Transparent

How to change shape of leading in ListTile in Flutter?

I want to show an image in a ListTile widget which should looks something like this.
Here is my code:
Padding(
padding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 20.0),
child: Card(
color: Colors.white,
child: ListTile(
leading: Container(
child: Image.network((orientation == Orientation.portrait
? image.portrait
: image.landscape),
fit: BoxFit.cover)
),
title: Text(terms[index].title),
subtitle: Text(terms[index].videoNumber.toString() + " Videos"),
trailing: Icon(
Icons.arrow_forward_ios,
color: Colors.lightBlueAccent,
),
),
),
);
This results in below output
What should I do so the image looks spread out as above.
You can set the padding of ListTile to 0:
...
child: ListTile(
contentPadding: EdgeInsets.all(0),
leading: ...
);
But even so, you can see that the leading only take the upper half, not the entire height of the card:
...
Card(
color: Colors.blue,
child: ListTile(
contentPadding: EdgeInsets.all(0),
leading: ...
Which result in:
You can use a Stack to include both ListTile and the leading Icons but lots of things have to be hardcorded. In this case, I recommend using ClipRRect with Row:
Padding(
padding: EdgeInsets.symmetric(
vertical: 0.0, horizontal: 20.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
height: 70,
color: Colors.white,
child: Row(
children: <Widget>[
Container(
color: Colors.red,
width: 70,
height: 70,
child: Icon(Icons.cake, color: Colors.white),
),
SizedBox(width: 10),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text('Test Title'),
Text('Test Video',
style: TextStyle(color: Colors.grey))
],
),
),
Icon(Icons.arrow_forward_ios,
color: Colors.blue),
],
),
),
),
);
Result:
Widget buildCard(_user) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
child: Card(
color: Colors.blue.shade100,
child: Row(
children: <Widget>[
Container(
margin: const EdgeInsets.all(0),
decoration: BoxDecoration(
color: Colors.blue.shade200,
shape: BoxShape.rectangle,
borderRadius:const BorderRadius.only(
topLeft: Radius.circular(4.0),
bottomLeft: Radius.circular(4.0),
),
),
width: 20,
height: 73,
),
const SizedBox(width: 10),
Expanded(
child: ListTile(
title: Text('${_user.state?.email!.substring(0, 6)}'),
subtitle: Text('${_user.state?.createdAt}'),
),
),
//const Icon(Icons.arrow_forward_ios, color: Colors.blue),
],
),
),
),
);
}

Card size not being adjusted when wrapped in a container

In my flutter app I have a GridView in which I list cards. In the cards I want to have an image and some text. I am trying to do this as follows:
import 'package:flutter/material.dart';
class Home extends StatefulWidget{
#override
State<StatefulWidget> createState() {
return HomeState();
}
}
class HomeState extends State<Home>{
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.green,
Colors.teal,
]
)
),
),
Padding(
padding: const EdgeInsets.only(top: 65),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.white60, width: 2.0)
),
padding: EdgeInsets.all(8),
child: CircleAvatar(
backgroundColor: Colors.white,
child: Icon(Icons.restaurant, size: 120,),
),
),
]
),
SizedBox(
height: 8,
),
Text(
"Genesis Technologies",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
color: Colors.white
),
),
SizedBox(
height: 6,
),
Text(
"Please take the following precautions",
style: TextStyle(
fontSize: 16,
color: Colors.white70
),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 350),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
)
),
),
Container(
margin: EdgeInsets.only(top: 250),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30)
)
),
child: Padding(
padding: EdgeInsets.all(0),
child: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
children: <Widget>[
Container(
height: 200,
width: 100,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)
),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(Icons.restaurant, size: 120,),
Text(
"Cover your mouth and nose when yous sneeze or cough",
style: TextStyle(
fontWeight: FontWeight.bold
),
),
],
),
),
),
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)
),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(Icons.restaurant, size: 120,),
Text(
"Avoid touching your face with unwashed hands",
style: TextStyle(
fontWeight: FontWeight.bold
),
),
],
),
),
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)
),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(Icons.restaurant, size: 120,),
Text(
"Stay home if you don't need to get out for critical matters",
style: TextStyle(
fontWeight: FontWeight.bold
),
),
],
),
),
),
],
)
),
),
],
),
),
),
);
}
}
And this renders the list of cards fine. My problem is that the cards bottom is being overflowed. I wrap the card in a container to fix this which looks like the follows:
Container(
height: 200,
width: 100,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)
),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(Icons.restaurant, size: 120,),
Text(
"Some text here",
style: TextStyle(
fontWeight: FontWeight.bold
),
),
],
),
),
),
),
I don't understand why this is happening. Any help would be appreciated. Thanks.
ok... I usual don't do that but I had to rework the whole structure because most of the things didn't make any sense. Now I don't really understand.. Why do you want cards to increase size to not overflow.. Did you mean decrease size? The cards in your grid view will be always the same because you use grid view. You have set crossAxisCount to 2 so 2 items in x axis and square.. If you add more, then on smaller screen they will be accessible by scrolling and will not overflow. I have set position of the container where you have all your cards from the top to 1/3 of the screen height which perhaps is better then hardcoding it to fixed size as you had. Try it and let me know if you need to adjust it in any other way.
UPDATE
Scaffold(
body: Column(children: [
Flexible(
flex: 2,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Colors.green,
Colors.teal,
])),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flexible(
flex: 1,
child: FractionallySizedBox(
heightFactor: 0.5,
child: Container(
width: 100,
decoration: BoxDecoration(
shape: BoxShape.circle,
border:
Border.all(color: Colors.white60, width: 2.0)),
padding: EdgeInsets.all(8),
child: CircleAvatar(
backgroundColor: Colors.white,
child: Icon(
Icons.restaurant,
),
),
),
),
),
SizedBox(
height: 8,
),
Text(
"Genesis Technologies",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
color: Colors.white),
),
SizedBox(
height: 6,
),
Text(
"Please take the following precautions",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16, color: Colors.white70),
),
],
),
),
),
Flexible(
flex: 3,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Colors.green,
Colors.teal,
])),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30))),
child: Padding(
padding: EdgeInsets.all(0),
child: GridView(
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2),
children: <Widget>[
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(
Icons.restaurant,
size: 120,
),
Text(
"Cover your mouth and nose when yous sneeze or cough",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(
Icons.restaurant,
size: 120,
),
Text(
"Avoid touching your face with unwashed hands",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Container(
margin: EdgeInsets.all(4),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Icon(
Icons.restaurant,
size: 120,
),
Text(
"Stay home if you don't need to get out for critical matters",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
),
],
)),
),
),
),
]),
);

Flutter set Container background with Text child

in flutter i want to have simple Text inside Container with background color on container, for example:
unfortunately i can't set or make this screen shot with flutter widgets
Expanded(
child: Container(
margin: EdgeInsets.only(top: 10.0),
child: ListView(
children: <Widget>[
Container(
padding: EdgeInsets.only(right: 1.0, left: 1.0),
child: Center(
child: bottomSheetDashBoardItems(
widget.dashboardItems),
),
), //container
], //list view children
), //list view
), //container
), //Expanded
Widget bottomSheetDashBoardItems(List<DashboardItems> dashboardItems) {
return Wrap(
children: dashboardItems
.map((item) => Container(
width: 75.0,
height: 75.0,
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(5.0)),
boxShadow: [
BoxShadow(
blurRadius: 0.5,
color: Colors.black,
offset: Offset(0.0, 0.0),
)
]),
child: Center(
child: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: Align(
alignment: Alignment.center,
child: Image.asset(
item.icon,
width: 40.0,
height: 40.0,
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
decoration: BoxDecoration(
color: Colors.indigo[400],
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5.0),
bottomRight: Radius.circular(5.0),
),
),
child: Padding(
padding: const EdgeInsets.only(top: 3.0),
child: Text(
item.title,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontFamily: 'IranSansLight',
fontSize: 9.0),
),
),
),
),
],
)),
))
.toList());
}
result:
Align(
alignment: Alignment.bottomCenter,
child: Container(
// width: 75.0, <--- remove this width and try
height: 19.0,
decoration: BoxDecoration(
color: Colors.indigo[400],
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5.0),
bottomRight: Radius.circular(5.0),
),
),
hope work
#1
Do not initiate widget tree through functions. Create a class under StatelessWidget instead. For more info check out this answer.
#2
As for the red bar not auto expanding in width - since you already use Stack, I can suggest a simple solution.
Replace Align (2nd child of Stack) with Positioned like this:
Positioned(
left: 0,
right: 0,
bottom: 0,
height: 19,
child: // ...
)
And remove width property of the Container.
Let me know if this helped.