Flutter screen height issue - flutter

I have issue my screen showing orange line in end and show ing error of A Renderflex overflowed by 5105 pixels on the bottom .
My code
class Orderlist extends StatelessWidget {
final posts;
Orderlist({Key key, this.posts}) : super(key: key);
#override
Widget build(BuildContext context) {
double stackWidth = MediaQuery.of(context).size.width;
double stackHeight = MediaQuery.of(context).size.height;
return SingleChildScrollView(
child: Column(
children: [
test(),
test(),
test(),
test(),
test()
],
),
);
}
}
class test extends StatelessWidget {
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Container(
color: Color(0xfff6f6f6),
child: Padding(
padding: const EdgeInsets.all(14.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
color: Color(0xfff8f8f8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
'asdada',
style: TextStyle(
fontFamily: 'SFPROBOLD',
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.bold),
),
Text(
'asda'
.toString(),
style: TextStyle(
color: Colors.grey, fontSize: 14))
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: width * 0.13,
decoration: BoxDecoration(
color: Color(0xffef9500),
borderRadius: BorderRadius.all(
Radius.circular(5))),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Center(
child: Text('Pending',
style: TextStyle(
fontFamily: 'SFPROBOLD',
color: Colors.white,
fontSize: 9))),
),
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.all(13.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
'Delivery',
style: TextStyle(
fontFamily: 'SFPROBOLD',
color: Color(0xffea6c7b),
fontSize: 13),
),
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: Text(
'asdada',
style: TextStyle(fontSize: 15),
),
),
IconButton(
icon: Icon(
Icons.arrow_forward,
color: Colors.grey,
),
onPressed: () {
// do something
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
OrderDetails()),
);
},
)
],
)
],
),
)
],
),
),
),
);
}
}
Try to wrap the first widget with SingleScrollview but its not working. Also try to wrap the Listviewbuilder but still showing pixels error and if i wrap SignleScrollview with expanded then its showing parent directory error

I think the error is because you wrapped the column in ListView as well as SingleChildScrollView. Try removing any one of them.

Related

CupertinoPageRoute shifting content upwards when pushing to a new page

I've been developing an app and noticed that the CupertinoPageRoute keeps pushing content upwards when going to a new page. This is quite annoying as it creates a lag/stutter effect.
Here is an image demonstrating this issue:
Incorrect UI
Meanwhile this is how the UI is supposed to look:
Correct UI
Here is a video:
https://vimeo.com/798133261
My code:
WelcomePage({Key? key}) : super(key: key);
final TextEditingController emailEditingController = TextEditingController();
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Stack(
children: [
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
"Welcome!",
style: TextStyle(fontSize: 36, fontWeight: FontWeight.bold),
),
SizedBox(height: 5),
Text(
"Sign up to see what your friends are listening to!",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.normal,
),
textAlign: TextAlign.center,
),
SizedBox(height: 100),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(16.0),
child: Image.asset(
'assets/images/icons/app/app_icon_transparent.png',
width: 50,
height: 50,
),
),
],
),
Padding(
padding: const EdgeInsets.only(bottom: 30),
child: Column(
children: [
ThirdPartySignIn(),
Padding(
padding: const EdgeInsets.only(top: 15),
child: CupertinoButton(
onPressed: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => SignupPage(),
),
);
},
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Container(
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
CustomColors.accentColor,
CustomColors.accentColor
],
),
),
child: const Center(
child: Text(
"Sign up",
style: TextStyle(
fontSize: headlineLabelFontSize,
fontWeight: FontWeight.w500,
color: CupertinoColors.white),
),
),
),
),
),
],
),
),
],
),
],
),
),
);
}
}
At first, I thought that the issue was with the Stack widget, however I tried using a column widget and recieved the same effect. I am not sure if this is a bug but I am sure that there is a possible work around. Thank you.
To fix this problem, I just had to add resizeToAvoidBottomInset: false to my main scaffold, and the page stopped resizing.

How can I center Row widget in container Flutter?

I want to center the Row widget in Container but can't do it.
Desire Design
My desire Design look like this : -
but I'm getting this output
My Output : -
Here is my code : -
Container(
height: Dimensions.height40,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(Dimensions.radius10), color: Colors.white),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: Dimensions.width45),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("assets/images/g.png", width: Dimensions.width20 + 5),
SmallText(text: LanguageStringKeys.instance.continueWithGoogle.tr)
],
),
),
),
SmallText
class SmallText extends StatelessWidget {
final Color? color;
final String text;
final double size;
final TextAlign? align;
const SmallText({
Key? key,
this.color = const Color(0xffCF1357),
this.size = 16,
required this.text, this.align=TextAlign.center,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Text(
text,
textAlign: align,
style: TextStyle(
color: color, fontSize: size, fontFamily: 'ROCK'),
);
}
}
Replace your Row widget
From
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("assets/images/g.png", width: Dimensions.width20 + 5),
SmallText(text: LanguageStringKeys.instance.continueWithGoogle.tr)
],
),
To
Row(
children: [
Icon(Icons.chevron_right_outlined, color: Colors.red),
Expanded(
child: Text(
"asdfasdfasdfadsfadsf",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.red, fontSize: 12, fontFamily: 'ROCK'),
),
),
],
),
try this way...
Container(
height: Dimensions.height40,
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(Dimensions.radius10), color: Colors.white),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: Dimensions.width45),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Image.asset("assets/images/g.png", width: Dimensions.width20 + 5),
),
SmallText(text: LanguageStringKeys.instance.continueWithGoogle.tr)
// if text overflowing
// Expanded(child: Text('text', maxLines: 2)),
],
),
),
),
Try below code:
ElevatedButton(
onPressed: () {},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.network(
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTffY2_D5YjjG8Mn3NnOFrXG2Piu72Ff5rbyHiyZXFvkWWtE3pLojAwOXpxAbC7PZa0JpU&usqp=CAU',
height: 40,
), //use your google image here
Text(
'Sign in with Google',
style: TextStyle(
color: Colors.black,
),
),
SizedBox()
],
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white, fixedSize: const Size(250, 50)),
),
Result->

A page I made was fine last night but now only shows me black and red

I don't know what I did wrong.
import 'package:flutter/material.dart';
import 'package:nle_app/models/stall.dart';
import 'package:nle_app/constants/colors.dart';
class StallInfo extends StatelessWidget {
final stall = Stall.generateRestaurant();
#override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 40),
padding: const EdgeInsets.symmetric(horizontal: 25),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
stall.name,
style: const TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
Row(
children: [
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.blueGrey.withOpacity(0.4),
borderRadius: BorderRadius.circular(5),
),
child: Text(
stall.label,
style: const TextStyle(
color: Colors.white,
),
)),
const SizedBox(
width: 10,
),
],
)
],
),
ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image.asset(
stall.logoUrl,
width: 80,
),
),
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
stall.desc,
style: const TextStyle(fontSize: 16),
),
Row(
children: [
const Icon(
Icons.star_outline,
color: Colors.amber,
),
Text(
'${stall.score}',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 15),
],
)
],
)
],
),
);
}
}
The image I uploaded shows what its suppossed to look like but in case you missed it, it's supposed to look like .
I thought maybe the image overflowed to the right but even when I remove the image it's the same thing.
I've tested it on different devices but it's all the same. It doesn't even throw an exception or anything. Does anyone know how to fix this.
It is missing material, Check if the parent widget contains Scaffold. Also for this one , you can wrap with any material widget like Material, Card,Scaffold....
Widget build(BuildContext context) {
return Material(
child: Container(
```

Flutter: Pressing on Card Widget in ListView Not Working

I have ListView builder adsList which contains LstTiles adTile contains the Card.
When I press the Card widget I expect an action and to navigate to another screen or just print in console, but nothing happens although I wrapped the card inside GestureDetector.
here is the code
class _AdTileState extends State<AdTile> {
#override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(top: 8),
child: GestureDetector(
onTap: (){
print('card pressed');
Navigator.push(context, new MaterialPageRoute(builder: (context) => AdView()));
},
child: Card(
margin: EdgeInsets.fromLTRB(20, 6, 20, 0),
child: ListTile(
trailing: Image.network(widget.adModel.adImage),
title: Text(widget.adModel.adName),
subtitle: Text(widget.adModel.location),
),
),
),
);
}
}
Here is the code inside AdList:
class _AdsListState extends State<AdsList> {
#override
Widget build(BuildContext context) {
final ads = Provider.of<List<AdModel>>(context);
return ListView.builder(
scrollDirection: Axis.vertical,
itemCount:(ads == null) ? 0 : ads.length,
itemBuilder: (context, index){
return
CustomAdTile(adModel: ads[index],);
});
}
}
And here is the code on the Page which show the ListView Builder:
Widget build(BuildContext context) {
return StreamProvider<List<Profile>>.value(
value: DatabaseService().profiles,
child: StreamProvider<List<AdModel>>.value(
value: DatabaseService().ads,
child: Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
appBar: AppBar(),
body: Column(
children: <Widget>[
Container(),
Row(),
Expanded(
child: AdsList()
),
],
),
Code for CustomAdTile:
class _CustomAdTileState extends State<CustomAdTile> {
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 3,
child: Padding(
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 10.0, 0.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.adModel.adName,
style: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 14.0,
),
),
const Padding(padding: EdgeInsets.symmetric(vertical: 2.0)),
Text(
widget.adModel.location,
style: const TextStyle(fontSize: 10.0),
),
const Padding(padding: EdgeInsets.symmetric(vertical: 1.0)),
Text(
'${widget.adModel.category} views',
style: const TextStyle(fontSize: 10.0),
),
],
),
),
),
const Icon(
Icons.more_vert,
size: 16.0,
),
Container(
height: 80,
width: 80,
decoration: BoxDecoration(
image: DecorationImage(image: NetworkImage(widget.adModel.adImage),
fit: BoxFit.fill),
),
)
],
),
);
}
}
It looks like you are never using AdTile, you are using CustomAdTile. You need to add the onTap inside CustomAdTile.
Here is the updated code for CustomAdTile.
class _CustomAdTileState extends State<CustomAdTile> {
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: InkWell(
///Add onTap here
onTap: () {
print('card pressed');
Navigator.push(
context, new MaterialPageRoute(builder: (context) => AdView()));
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 3,
child: Padding(
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 10.0, 0.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.adModel.adName,
style: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 14.0,
),
),
const Padding(padding: EdgeInsets.symmetric(vertical: 2.0)),
Text(
widget.adModel.location,
style: const TextStyle(fontSize: 10.0),
),
const Padding(padding: EdgeInsets.symmetric(vertical: 1.0)),
Text(
'${widget.adModel.category} views',
style: const TextStyle(fontSize: 10.0),
),
],
),
),
),
const Icon(
Icons.more_vert,
size: 16.0,
),
Container(
height: 80,
width: 80,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(widget.adModel.adImage),
fit: BoxFit.fill),
),
)
],
),
),
);
}
}

Flutter Container - How to align child text without changing container width?

I am trying to build something similar to a chat bubble, where each chat bubble would have text aligned normally, and timestamp aligned to the bottom right of the bubble. The size of the bubble must expand with the text, and should not take more space than necessary.
In order to do this I used a Column with two Container children. The second child would be having the timestamp.
When I do this without adding "alignment" property to the second Container child, the bubble size correctly shrinks/expands to the text, like so:
But when I add alignment: Alignment.bottomRight to the second container, the bubble size expands to fill the entire width of the screen.
Is there a way to align the "7:30 PM" text to the bottom right of the bubble without expanding the bubble size?
Scaffold(
body: Container(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
child: Text(
"Without Alignment",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
),
Container(
// alignment: Alignment.bottomRight,
decoration: BoxDecoration(
border: Border.all(),
),
child: Text(
"7:30 PM",
textDirection: TextDirection.rtl,
textAlign: TextAlign.right,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
),
],
),
),
),
This may help you
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: MainWidget(),
);
}
}
class MainWidget extends StatefulWidget {
#override
_MainWidgetState createState() => _MainWidgetState();
}
class _MainWidgetState extends State<MainWidget> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
shrinkWrap: true,
children: <Widget>[
ReceivedMessageBubble(
message:
"This is a demo message send by XXXX. So don't reply it. Trying to making it multiple lines. You can increase it",
time: "12:45 PM",
),
SendMessageBubble(
message:
"Oh!!! OK",
time: "12:45 PM",
),
],
),
);
}
}
class SendMessageBubble extends StatelessWidget {
final String message;
final String time;
const SendMessageBubble({
Key key,
this.message,
this.time,
}) : assert(message != null),
assert(time != null),
super(key: key);
#override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
double maxBubbleWidth = constraints.maxWidth * 0.7;
return Align(
alignment: Alignment.centerRight,
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxBubbleWidth),
child: Container(
decoration: BoxDecoration(
color: Colors.blue[300],
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(0.0),
bottomLeft: Radius.circular(10.0),
bottomRight: Radius.circular(10.0),
),
),
margin: const EdgeInsets.all(10.0),
padding: const EdgeInsets.all(10.0),
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(message),
const SizedBox(height: 5.0),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
time,
style: const TextStyle(
color: Colors.black54,
fontSize: 10.0,
),
),
],
)
],
),
),
),
),
);
},
);
}
}
class ReceivedMessageBubble extends StatelessWidget {
final String message;
final String time;
const ReceivedMessageBubble({
Key key,
this.message,
this.time,
}) : assert(message != null),
assert(time != null),
super(key: key);
#override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
double maxBubbleWidth = constraints.maxWidth * 0.7;
return Align(
alignment: Alignment.centerLeft,
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: maxBubbleWidth,
),
child: Container(
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(0.0),
topRight: Radius.circular(10.0),
bottomLeft: Radius.circular(10.0),
bottomRight: Radius.circular(10.0),
),
),
margin: const EdgeInsets.all(10.0),
padding: const EdgeInsets.all(10.0),
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(message,),
const SizedBox(height: 5.0),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text(
time,
style: const TextStyle(
color: Colors.black54,
fontSize: 10.0,
),
),
],
)
],
),
),
),
),
);
},
);
}
}
Here is the Demo DartPad
i edited my answer, try this :
Column(crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
child: Text(
"Without Alignment",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
),
Container(
//alignment: Alignment.bottomRight,
//constraints: BoxConstraints.expand(),
decoration: BoxDecoration(
border: Border.all(),
),
child: Text(
"7:30 PM",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
),
],
);
try this, it's work on me..
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 300,
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.blue,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
"Without Alignment",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border.all(),
),
child: Text(
"7:30 PM",
textDirection: TextDirection.rtl,
textAlign: TextAlign.right,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
),
],
)
],
),
),
),