Related
How do i make the login text and sign in text to start from a single margin rather than the alignment it is shown in the picture?
Here the text isnt being aligned from a single margin and has off placement between texts
Code for it:
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(
width: double.infinity,
height: 200,
),
const Divider(
thickness: 3,
color: Colors.white,
indent: 160,
endIndent: 160,
),
Container(
decoration: const BoxDecoration(
color: Color.fromRGBO(32, 32, 32, 1),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
),
width: double.infinity,
height: MediaQuery.of(context).size.height,
child: Align(
alignment: Alignment.topLeft,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Column(
children: [
Text(
'Login',
textAlign: TextAlign.start,
style: GoogleFonts.inter(
textStyle: const TextStyle(
color: Colors.white,
fontSize: 32,
fontWeight: FontWeight.bold),
),
),
Text(
'Sign in to continue',
style: GoogleFonts.inter(
color: Color.fromRGBO(161, 161, 161, 1),
fontSize: 24,
fontWeight: FontWeight.w300),
)
],
),
)
],
),
),
),
],
),
Set the crossAxisAlignment property of the Column to start:
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
...]
)
Add CrossAxisAlignment.start to immediate parent column of text.
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, //here
children: [
Text(
'Login',
),
Text(
'Sign in to continue',
)
],
),
)
Edit: should be crossAxisAlignment.
Set the mainAxisAlignment attribute for the Column:
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
...
I'm trying to code a web site with Flutter.
I have a screen like this:
The text in the middle is just a little bit below. I want to take it a little higher. How can I do that?
Codes:
body: ListView(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("indexBackground.gif"),
colorFilter: ColorFilter.mode(Colors.blue.withOpacity(0.4), BlendMode.dstATop),
fit: BoxFit.cover,
),
),
height: MediaQuery.of(context).size.height - 55,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("3D Modelleme Hizmeti", style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold, color: Colors.black),),
),
),
],
),
),
],
),
Thanks in advance for your help.
One way would be to use the EdgeInsets.fromLTRB constructor. In this example I increased the bottom padding to 30.0 which will raise up the text, you should adjust it to what works best for you.
padding: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 30.0),
Try this:
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("indexBackground.gif"),
colorFilter: ColorFilter.mode(
Colors.blue.withOpacity(0.4), BlendMode.dstATop),
fit: BoxFit.cover,
),
),
height: MediaQuery.of(context).size.height - 55,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"3D Modelleme Hizmeti",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
color: Colors.black),
),
),
),
],
),
),
],
),
),
How to achieve the following design in Flutter?
I wanted to implement
but I get this result
I have three Containers. Main container inside that two more container placed horizontally And I want to position Icon to the top right corner of the main Container.
Below is my code
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(
top: widget.index != 0 ? 18 : 0,
),
child: Row(children: <Widget>[
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Container(
width: 354,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 3.0,
),
],
border: Border.all(
color: Colors.white,
width: 1,
)),
padding: EdgeInsets.only(left: 3),
child: Row(
children: <Widget>[
Container(
height: 85.0,
width: 85.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Colors.grey.shade50,
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Image(
image: AssetImage(
'${widget.restaurantListModelObj.restImage}'),
),
),
),
SizedBox(
width: 10.0,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
widget.restaurantListModelObj.restaurantName,'),
),
Icon(Icons.bookmark_border_outlined,
color: Colors.orange, size: 17),// this
icon i wanted to top right corner of main container.
],
),
),
Padding(
padding: const EdgeInsets.all(5.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
widget.restaurantListModelObj.foodCategory,
),
SizedBox(
width: 30,
),
Text(
'${widget.restaurantListModelObj.distance} Km',
),
],
),
),
Padding(
padding: const EdgeInsets.all(5.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(Icons.star, color: Colors.orange, size: 17),
Text(
'${widget.restaurantListModelObj.restReview}',
),
SizedBox(
width: 35,
),
Icon(Icons.watch_later_outlined, size: 17),
Text(
'${widget.restaurantListModelObj.distanceFromLocation} Mins',
),
SizedBox(
width: 35,
),
Text(
widget.restaurantListModelObj.restStatus,
),
],
),
),
],
)
],
),
),
),
),
]),
);
}
I don't understand how to do this.
There are many ways for doing that. If you want to have full control over the exact location of your widget. wrap the container in a Stack widget. Then put your icon in another container, and put it in the same Stack widget.
Once you do that, you can control the exact location of your widget using the Align widget. Here's an example:
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(
top: 18,
),
child: Row(children: <Widget>[
Stack(
children: [
Container(
width: 354,
height: 400,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white,
border: Border.all(
color: Colors.grey,
width: 1,
)),
padding: EdgeInsets.only(left: 3),
),
Container(
width: 354,
height: 400,
child: Align(
alignment: Alignment(1, -1),
//Alignment(1, -1) place the image at the top & far left.
//Alignment (0, 0) is the center of the container
//You can change the value of x and y to any number between -1 and 1
child: Icon(Icons.bookmark_border_outlined,
color: Colors.orange, size: 17),
),
),
],
),
]),
);
}
Wrap restaurant name with Expended widget
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"Restaurant Name",
),
),
Icon(Icons.bookmark_border_outlined),
],
);
There are many ways to achieve this. I have done as follows. Design your items as per desired. I had only worked on layout placement.
Container(
padding: EdgeInsets.all(10),
height: 110,
width: MediaQuery.of(context).size.width,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 3.0,
),
],
border: Border.all(
color: Colors.white,
width: 1,
)),
padding: EdgeInsets.only(left: 3),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: 85.0,
width: 85.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Colors.grey.shade50,
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Image(
image: NetworkImage(
'https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/1200px-Image_created_with_a_mobile_phone.png',
),
fit: BoxFit.contain,
// image: AssetImage(
// '${widget.restaurantListModelObj.restImage}'),
// ),
),
),
// ),
),
SizedBox(
width: 10.0,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Text("Restaurant Name",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
)),
],
),
SizedBox(height: 5),
Row(children: [
Text("Fast Food"),
SizedBox(width: 15),
Text("21 Km"),
]),
SizedBox(height: 5),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Row(children: [
Icon(Icons.star),
SizedBox(width: 5),
Text("4.3")
]),
SizedBox(width: 5),
Row(children: [
Icon(Icons.timer),
SizedBox(width: 5),
Text("56 mins")
]),
SizedBox(width: 5),
Row(children: [
Icon(Icons.calendar_today),
SizedBox(width: 5),
Text("OPen")
]),
])
]),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.topRight,
child: Icon(Icons.bookmark, color: Colors.orange)),
)
]),
))),
i want to know, how let the container height depend on length of text and cover it in container not in picture 2 if i setting text too long the text is come over container then how to fix it
on message by b-akused02 : it's short and still in height :100,
on message by b-akused01 : it's long over container
on message by b-akused03 : it's short and still in height :100,
Widget _buildCommentItem({#required CommentDetail commentDetail}) {
return Container(
height: 100,
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 20.0,
),
Expanded(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Container(
height: 45, //height, //155,
width: 45, //width, //155,
decoration: BoxDecoration(
color: const Color(0xff7c94b6),
image: DecorationImage(
image: NetworkImage(
commentDetail.otherUserProfileImageUrl),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(12),
),
),
),
Expanded(
flex: 8,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Wrap(
// crossAxisAlignment: CrossAxisAlignment.start,
children: [
FittedBox(
fit: BoxFit.cover,
child: Text(
commentDetail.otherUsername,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
Text(
commentDetail.comment,
style: TextStyle(
color: Colors.black,
),
),
],
),
),
),
],
),
),
),
SizedBox(
height: 20,
)
],
),
),
);
}
Wrap the given container in a Column and remove the height parameter from within.
Complete Code
Widget _buildCommentItem({#required CommentDetail commentDetail}) {
return Container(
child: Container(
child: Wrap(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Container(
height: 45, //height, //155,
width: 45, //width, //155,
decoration: BoxDecoration(
color: const Color(0xff7c94b6),
image: DecorationImage(
image: NetworkImage(
commentDetail.otherUserProfileImageUrl),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(12),
),
),
),
Expanded(
flex: 8,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Wrap(
// crossAxisAlignment: CrossAxisAlignment.start,
children: [
FittedBox(
fit: BoxFit.cover,
child: Text(
commentDetail.otherUsername,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
Text(
commentDetail.comment,
style: TextStyle(
color: Colors.black,
),
),
],
),
),
),
],
),
),
),
],
),
),
);
}
only create a Container without height.
Container(
width: 200, //for example
child: Text('any Text'),
)
Hi i am following an online tutorial building an app but am getting overflow pixels at the bottom of my card. I am unable to find the difference between my code from the video and the source code is not provided by the author. From my understanding i am having a
Column(children:[ClipRRect,Row]) <- in general but i cannot see the Row it is behind the ClipRRect, shouldn't it be below?
final String imagePath, cityName, monthYear, discount;
final int oldPrice, newPrice;
CityCard(this.imagePath, this.cityName, this.monthYear, this.discount,
this.oldPrice, this.newPrice);
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
child: Stack(
children: <Widget>[
Container(
height: 210,
width: 160,
child: Image.asset(
imagePath,
fit: BoxFit.cover,
),
),
Positioned(
left: 0.0,
bottom: 0.0,
height: 60,
width: 160,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [
Colors.black,
Colors.black.withOpacity(0.1)
]),
),
),
),
Positioned(
left: 10,
bottom: 10,
right: 10,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
cityName,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 18),
),
Text(
monthYear,
style: TextStyle(
fontWeight: FontWeight.normal,
color: Colors.white,
fontSize: 14),
)
],
),
Container(
padding: EdgeInsets.symmetric(
horizontal: 6.0, vertical: 2.0),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: Text(
"$discount%",
style: TextStyle(fontSize: 14, color: Colors.black),
),
),
],
),
),
],
),
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: 5.0),
Text(
'${formatCurrency.format(newPrice)}',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
SizedBox(width: 5.0),
Text(
"(${formatCurrency.format(oldPrice)})",
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.normal,
fontSize: 13),
),
],
),
],
),
);
}
}```
I am suppose to have a row that shows the new price and the old price below each card. I am able to reveal them if i reduce the height of the Card container but i have no idea why it is overlapping since i am having a Column(children:(ClipRRect,Row)) <- can't see the Row
Try to add your Column inside a SingleChildScrollView
Probably this didn't happen to your instructor because of the size of his device.
For the bottom overflow pixels, place the Column in SingleChildScrollView for instance:
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: SingleChildScrollView(
child: Column(
**your code**)));}