Bottom Overflowed by 17 pixels [Flutter] - flutter

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**)));}

Related

How to align text in a way it starts from a margin in flutter?

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: [
...

how to guarantee that the box that contains date and time will be always centered after calling the card in list view

i am a beginner in flutter , i am trying to correct the display of this widget in flutter ,
the problem is that this widget is not responsive where the name of the teams when they are long they can make the screen out of range , and also the time and date zone is not always centered , i am searching how to make the date and the time zone always centered in the screen in all the cases , how to replace the padding ? by container?? what prosperities to change???
my goal is to make the date and the time centered in all the cases and my second goal is to find a solution for the width of screen when the name of teams are long
here my widget class :
import 'package:flutter/material.dart';
class BroadcastSchedule extends StatelessWidget {
String home;
String homeImage;
String away;
String awayImage;
String time;
String date;
BroadcastSchedule(this.home,this.homeImage,this.away,this.awayImage,this.time,this.date);
#override
Widget build(BuildContext context) {
return Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child:
Row(
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(this.homeImage),
),
const SizedBox(width:10.0),
Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget> [
Text(this.home),
const SizedBox(height: 5.0, ),
],
),
Padding(
padding: EdgeInsets.only(top:20.0, left: 20.0, right: 20.0),
child: Container(
padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: Colors.grey[700],
borderRadius: BorderRadius.circular(11.0),
),
child: Column(
children: [
Text(this.time,style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: Colors.white,
),),
const SizedBox(height: 5.0, ),
Text(this.date,style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16.0,
color: Colors.white
),),
],
),
),
),
Expanded(
child : Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget> [
Text(this.away),
const SizedBox(height: 5.0, ),
],
),
),
Spacer(),
CircleAvatar(
backgroundImage: NetworkImage(this.awayImage),
),
],
),
),
);
}
}
here the screen capture :
how can we replace padding that contains the date and time of a match by something that will be centered in all the cases
I Think you're looking for this.
final Result Looks like this.
Final Ouput
class BroadcastSchedule extends StatelessWidget {
final String home;
final String homeImage;
final String away;
final String awayImage;
final String time;
final String date;
BroadcastSchedule({
this.home,
this.homeImage,
this.away,
this.awayImage,
this.time,
this.date,
});
#override
Widget build(BuildContext context) {
return Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: <Widget>[
Expanded(
flex: 1,
child: Row(
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(this.homeImage),
),
SizedBox(
width: 10.0,
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(this.home),
const SizedBox(
height: 5.0,
),
],
),
),
],
),
),
Expanded(
flex: 1,
child: Padding(
padding: EdgeInsets.only(top: 20.0, left: 20.0, right: 20.0),
child: Container(
padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: Colors.grey[700],
borderRadius: BorderRadius.circular(11.0),
),
child: Column(
children: [
Text(
this.time,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: Colors.white,
),
),
const SizedBox(
height: 5.0,
),
Text(
this.date,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16.0,
color: Colors.white),
),
],
),
),
),
),
Expanded(
flex: 1,
child: Row(
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
this.away,
overflow: TextOverflow.fade,
),
SizedBox(
height: 5.0,
),
],
),
),
CircleAvatar(
backgroundImage: NetworkImage(this.awayImage),
),
],
),
),
],
),
),
);
}
}
Column(crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget> [
Text(this.home),
const SizedBox(height: 5.0, ),
],
),
Please change it. Don't use the column it's unneccessary.
Instead, You can use a container of fixed-sized (fixed height and width). So, that it can wrap text according to its length.
The problem caused by the length of this.home string. You can wrap that text inside the container of fixed length. so, that your date and time is shown always at the center.
Try this code,
import 'package:flutter/material.dart';
class BroadcastSchedule extends StatelessWidget {
String home;
String homeImage;
String away;
String awayImage;
String time;
String date;
BroadcastSchedule(this.home,this.homeImage,this.away,this.awayImage,this.time,this.date);
#override
Widget build(BuildContext context) {
return Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child:
Row(
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(this.homeImage),
),
const SizedBox(width:10.0),
Spacer(),
Container(
width: MediaQuery.of(context).size.width * 0.22,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget> [
Text(this.home,softWrap: true,),
const SizedBox(height: 5.0, ),
],
),
),
Padding(
padding: EdgeInsets.only(top:20.0, left: 20.0, right: 20.0),
child: Container(
padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: Colors.grey[700],
borderRadius: BorderRadius.circular(11.0),
),
child: Column(
children: [
Text(this.time,style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: Colors.white,
),),
const SizedBox(height: 5.0, ),
Text(this.date,style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16.0,
color: Colors.white
),),
],
),
),
),
Expanded(
child : Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget> [
Text(this.away),
const SizedBox(height: 5.0, ),
],
),
),
Spacer(),
CircleAvatar(
backgroundImage: NetworkImage(this.awayImage),
),
],
),
),
);
}
}
IF it's not center try to change the length of the container.

Flutter Flexible Text is overflowing in Column

I am creating a list tile that has a leading image downloaded from the internet.
The image could be landscape or portrait.
Based on the image size space available for the title text change.
When the image get downloaded from the internet available space get re-adjusted.
To fix this problem I used Flexible widget and TextOverflow.ellipsis.
This works well until I add the Flexible to a column to add a sub heading.
Now I am getting overflow error for the longer title texts.
Any idea how to fix this?
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
constraints: BoxConstraints(minHeight: 50, maxHeight: 100),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
bottomLeft: Radius.circular(8)),
child: FadeInImage(
placeholder: AssetImage('images/placeholder-image.png'),
image: NetworkImage(post.imageURL),
fit: BoxFit.cover,
),
),
),
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
child: Container(
padding: const EdgeInsets.fromLTRB(8, 8, 5, 5),
child: new Text(
post.title,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Theme.of(context).primaryColor),
),
),
),
],
),
],
)
Wrap the Column with a Flexible instead of wrapping the Text with a Flexible:
Flexible(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: const EdgeInsets.fromLTRB(8, 8, 5, 5),
child: new Text(
post.title,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Theme.of(context).primaryColor),
),
),
],
),
),
Use Expanded
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
constraints: BoxConstraints(minHeight: 50, maxHeight: 100),
child: ClipRRect(
borderRadius: const BorderRadius.horizontal(
left: Radius.circular(8),
),
child: FadeInImage(
placeholder: NetworkImage('https://picsum.photos/100'),
image: NetworkImage('https://picsum.photos/100'),
fit: BoxFit.cover,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Title',
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Colors.white,
),
),
Text(
'Subtitle',
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Colors.white,
),
),
],
),
),
),
],
);
}
}

Flutter: How to place a button in the middle of 2 containers?

UI Layout
If the purple area is inside an Expanded widget, how would I go about to position the button? I've implemented that UI by setting a fixed height to the purple container but haven't been able to understand how to achieve the same effect if the height is variable, depending on the content.
I was able to get close by using Stack and Positioned widgets but then the button is not really clickable. If anyone can give me a general idea on how to achieve the desired goal I would be thankful.
Here's my attempt (demo case)
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
flex: 1,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.redAccent,
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Stack(
children: <Widget> [
Padding(
padding: const EdgeInsets.only(bottom: 40.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Icon(
Icons.book,
color: Colors.white,
size: 40.0
),
Container(
width: 90.0,
child: new Divider(color: Colors.white),
),
Text(
"Some random text -",
style: TextStyle(color: Colors.white, fontSize: 25.0),
),
Padding(
padding: const EdgeInsets.only(top: 8.0, right: 70.0),
child: Row(
children: <Widget>[
Flexible(
child: Text(
'More random text that can vary a lot!',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: <Widget>[
Text(
'Random text ',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: <Widget>[
Text(
'Random',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
),
Positioned(
bottom: 0.0,
left: MediaQuery.of(context).size.width - 100.0,
child: FractionalTranslation(
translation: const Offset(0.0, 0.8),
child: FloatingActionButton(
backgroundColor: Colors.white,
foregroundColor: Colors.redAccent,
child: new Icon(
Icons.map
),
onPressed: () {
},
),
),
),
]
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8.0, left: 8.0),
child: Row(
children: <Widget>[
Flexible(
child: Text(
"Random text",
style: new TextStyle(
fontFamily: 'Raleway',
fontSize: 16.0,
color: Colors.black38
)
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Random text - long text",
style: new TextStyle(
fontFamily: 'Raleway',
fontSize: 18.0
)
),
),
],
)
],
)
),
),
],
);
Explaining what I described in the comments:
You can use the FractionalTranslation widget to shift your FAB half way down.
FractionalTranslation(translation: Offset(0, .5), child: FloatingActionButton(...))
This requires you to have it positioned at the bottom of the purple area (referring to your screenshot) beforehand, but I assume that you have that figured out.

How can i make my Scaffold widget scrollable so i would not have a "Bottom overflowed by xx Pixels" Error

I have a flutter app, and i am trying to make it scrollable, because i am getting a
"Bottom overflowed by 34 Pixels", which i am sure is caused when my widget scrolls below the apportioned height of the screen, how can i solved this issue:
i followed this question to solve the issue, but noting happened :
this is my code:
return ListView(
children: <Widget>[
new Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
color: Colors.white,
image: DecorationImage(
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(0.3), BlendMode.dstATop),
image: AssetImage('images/space.gif'),
fit: BoxFit.cover,
),
),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 200.0, left: 40.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Start",
style: TextStyle(
decoration: TextDecoration.none,
color: Colors.black,
fontSize: 30.0,
),
),
Text(
"Your",
style: TextStyle(
decoration: TextDecoration.none,
color: Colors.black,
fontSize: 30.0,
),
),
Text(
"Adventure",
style: TextStyle(
fontWeight: FontWeight.bold,
decoration: TextDecoration.none,
color: Colors.black,
fontSize: 30.0,
),
),
],
),
),
new Container(
width: MediaQuery.of(context).size.width,
margin:
const EdgeInsets.only(left: 30.0, right: 30.0, top: 100.0),
alignment: Alignment.center,
child: new Row(
children: <Widget>[
new Expanded(
child: new RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
color: Colors.blue,
onPressed: () => gotoSignup(),
child: new Container(
padding: const EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 20.0,
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: Text(
"SIGN UP",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
],
),
),
),
),
],
),
),
new Container(
width: MediaQuery.of(context).size.width,
margin:
const EdgeInsets.only(left: 30.0, right: 30.0, top: 30.0),
alignment: Alignment.center,
child: new Row(
children: <Widget>[
new Expanded(
child: new RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
color: Colors.redAccent,
onPressed: () => gotoLogin(),
child: new Container(
padding: const EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 20.0,
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: Text(
"LOGIN",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
],
),
),
),
),
],
),
),
],
),
)
],
);
Solved this by removing the height: MediaQuery.of(context).size.height, attribute in the first container widget