Bottom Overflow Problem in Flutter Despite of Screen fixing(?!) - flutter

I was trying to make a responsive app that measure the screen height and than apply it's container's height according it. I split the app's page in (40%, 30% , 30%) portion, but the app showing the message "Bottom pixel overflow by 10.0 pixel".
And When I rotate the Scene, The middle portion container also show the same problem.
As A newbie, I Don't understand what is my wrong-doing or wrong-knowing?
Is the padding cause the problem?
And is there any simple or standard system to design a app responsive to various window ?
Thanks in Advance.
Here is my Code
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'TravelApp';
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
//title: _title,
home: Scaffold(
//appBar: AppBar(
//centerTitle: true,
//title: const Text(_title),
//),
body: MyStatelessWidget(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
dynamic screenHeight = MediaQuery.of(context).size.height;
dynamic screenwidth = MediaQuery.of(context).size.width;
return Scaffold(
body: Container(
height: screenHeight,
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomRight,
colors: [Color(0xFDEAEC), Colors.grey]),
),
// Portion Started In The Column
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
height: screenHeight * 0.40, //40% of Screen height
child: Image(
image: AssetImage('../assets/firstpag.jpg'),
),
),
Container(
alignment: Alignment.center,
height: screenHeight * 0.30, //30% of Screen height
color: Colors.green,
padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text(
"Let's Get Started",
style: TextStyle(fontSize: 25),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.fromLTRB(10, 15, 10, 0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing.Lorem Ipsum is simply dummy text of the printing",
style: TextStyle(
fontSize: 12,
),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
width: screenwidth * 0.20,
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
alignment: Alignment.center,
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.blue,
height: 4,
width: 10,
)
],
)),
],
),
),
Container(
alignment: Alignment.center,
height: screenHeight * 0.30, //30% of Screen height
color: Colors.red,
padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text(
"Let's Get Started",
style: TextStyle(fontSize: 25),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.fromLTRB(10, 15, 10, 0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing.Lorem Ipsum is simply dummy text of the printing",
style: TextStyle(
fontSize: 18,
),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
width: screenwidth * 0.20,
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
alignment: Alignment.center,
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.blue,
height: 4,
width: 10,
)
],
)),
],
),
)
],
),
));
}
}

The issue with the code above is that it is using a padding: EdgeInsets.all(5) which also means we're using 5px from the bottom and from the top as padding.
Therefore, the layout overflows by 10px.
A possible solution would be to either remove the padding or change it to horizontal-only, depending on the desired outcome:
padding: EdgeInsets.symmetric(horizontal: 5),
Full snippet code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'TravelApp';
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
//title: _title,
home: Scaffold(
//appBar: AppBar(
//centerTitle: true,
//title: const Text(_title),
//),
body: MyStatelessWidget(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
dynamic screenHeight = MediaQuery.of(context).size.height;
dynamic screenwidth = MediaQuery.of(context).size.width;
return Scaffold(
body: Container(
height: screenHeight,
padding: EdgeInsets.symmetric(horizontal: 5), // modified line
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomRight,
colors: [Color(0xFDEAEC), Colors.grey]),
),
// Portion Started In The Column
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
height: screenHeight * 0.40, //40% of Screen height
child: Image(
image: AssetImage('../assets/firstpag.jpg'),
),
),
Container(
alignment: Alignment.center,
height: screenHeight * 0.30, //30% of Screen height
color: Colors.green,
padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text(
"Let's Get Started",
style: TextStyle(fontSize: 25),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.fromLTRB(10, 15, 10, 0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing.Lorem Ipsum is simply dummy text of the printing",
style: TextStyle(
fontSize: 12,
),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
width: screenwidth * 0.20,
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
alignment: Alignment.center,
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.blue,
height: 4,
width: 10,
)
],
)),
],
),
),
Container(
alignment: Alignment.center,
height: screenHeight * 0.30, //30% of Screen height
color: Colors.red,
padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text(
"Let's Get Started",
style: TextStyle(fontSize: 25),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.fromLTRB(10, 15, 10, 0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing.Lorem Ipsum is simply dummy text of the printing",
style: TextStyle(
fontSize: 18,
),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
width: screenwidth * 0.20,
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
alignment: Alignment.center,
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.blue,
height: 4,
width: 10,
)
],
)),
],
),
)
],
),
));
}
}

Related

Width of container is not working inside SliverToBoxAdapter in CustomScrollView

I have a CustomScrollView contains a SliverToBoxAdapter.I gave width as MediaQuery.of(context).size.width / 1.75.But it takes full width of screen .
enter image description here.
Width of container is working if it is placed outside of Customscrollview.
class ProfileView extends GetView<ProfileController> {
const ProfileView({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Row(children: [
Expanded(
child: CustomScrollView(
shrinkWrap: true,
slivers: [
SliverToBoxAdapter(
child: Padding(
padding:
const EdgeInsets.only(top: 40.0, left: 45),
child: Container(
padding: EdgeInsets.only(top: 30),
width: MediaQuery.of(context).size.width / 1.75,
decoration: BoxDecoration(
border:
Border.all(color: Colors.red, width: 0.7),
color: Color(0xfffbfbfa),
),
child: Stack(
children: [
Positioned(
right: 0,
top: 0,
child: Align(
alignment: Alignment.topRight,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Padding(
padding: const EdgeInsets.only(
right: 18.0),
child: Text(
"Edit",
textAlign: TextAlign.left,
style: GoogleFonts.inter(
color: AppColors.primaryColor,
fontSize: 13,
letterSpacing:
0
,
fontWeight: FontWeight.w400,
height: 1.5769230769230769),
),
),
),
),
),
Text("Text"),
],
),
),
),
)
],
),
)
])
);
}
you have to wrap your container with Align widget like this:
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(top: 40.0, left: 45),
child: Align(
alignment: Alignment.center,
child: Container(
padding: const EdgeInsets.only(top: 30),
width: MediaQuery.of(context).size.width / 1.75,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 0.7),
color: Colors.amber,
),
....

what is equivalent of guidelines (constraint layout) in flutter?

I want to create view like image, the first view (blue view) is 30% of screen height
and the second view (red view) is center vertical of first view (15% of the first view from bottom to top, and 15% of the first view from bottom to bottom).
if in android XML constraint layout I can use guidelines to handle that, but in flutter what I can use to create like that view?
import 'package:flutter/material.dart';
import 'package:flutter_app2/custom_text.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => new _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
Card statsWidget() {
return new Card(
elevation: 1.5,
margin: EdgeInsets.only(bottom: 210.0, left: 20.0, right: 20.0),
color: Colors.white,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
verticalDirection: VerticalDirection.down,
children: <Widget>[
new Padding(
padding: EdgeInsets.all(20.0),
child: new Row(
children: <Widget>[
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Align(
alignment: Alignment.center,
child: new Text(
"Photos",
textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.grey,
fontSize: 16.0,
),
)),
new Align(
alignment: Alignment.center,
child: new Text(
"22k",
textAlign: TextAlign.center,
style: new TextStyle(
color: Color(0xff167F67),
),
)),
],
),
flex: 1,
),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Align(
alignment: Alignment.center,
child: new Text(
"Followers",
textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.grey,
fontSize: 16.0,
),
)),
new Align(
alignment: Alignment.center,
child: new Text(
"232k",
textAlign: TextAlign.center,
style: new TextStyle(
color: Color(0xff167F67),
),
)),
],
),
flex: 1,
),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Align(
alignment: Alignment.center,
child: new Text(
"Following",
textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.grey, fontSize: 16.0),
)),
new Align(
alignment: Alignment.center,
child: new Text(
"332k",
textAlign: TextAlign.center,
style: new TextStyle(
color: Color(0xff167F67),
),
)),
],
),
flex: 1,
)
],
),
)
],
));
}
#override
build(BuildContext context) {
return new Material(
type: MaterialType.transparency,
child: new Stack(
children: [
new Column(
children: <Widget>[
headerWidget(),
bodyWidget(),
],
),
new Center(
child: statsWidget(),
),
],
));
}
Widget headerWidget() {
var header= new Expanded(
child: new Container(
decoration: new BoxDecoration(
color: const Color(0xff167F67),
),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Center(
child: new Container(
margin: EdgeInsets.only(bottom: 10.0),
height: 80.0,
width: 80.0,
decoration: new BoxDecoration(
color: const Color(0xff167F67),
image: new DecorationImage(
image: new NetworkImage(
"https://4.bp.blogspot.com/-QXHUYmKycZU/W-Vv9G01aAI/AAAAAAAAATg/eF1ArYpCo7Ukm1Qf-JJhwBw3rOMcj-h6wCEwYBhgL/s1600/logo.png"),
fit: BoxFit.cover,
),
border:
Border.all(color: Colors.white, width: 2.0),
borderRadius: new BorderRadius.all(
const Radius.circular(40.0)),
),
),
),
new Text(
"Developer Libs",
textAlign: TextAlign.center,
style: new TextStyle(
color: Color(0xffffffff),
),
)
],
),
),
flex: 1,
);
return header;
}
Widget bodyWidget() {
var bodyWidget=new Expanded(
child: new Container(
decoration: new BoxDecoration(
color: const Color(0xffffffff),
),
child: new Padding(
padding:
EdgeInsets.only(left: 50.0, right: 50.0, top: 50.0),
child: new Column(
children: <Widget>[
new CustomText(
label: "contact#developerlibs",
textColor: 0xff858585,
iconColor: 0xff167F67,
fontSize: 15.0,
icon: Icons.email)
.text(),
],
),
)),
flex: 2,
);
return bodyWidget;
}
}
I found this code and it's good but If I try in other phone resolution the second view is not center of first view. like below image
you can play with something like this :
LayoutBuilder(
builder: (context, constraints) {
final firstHeight = constraints.biggest.height * .3;
final secondHeight = 200.0;
return SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: firstHeight + secondHeight / 2,
child: Stack(
children: [
Positioned(
top: 0,
height: firstHeight,
left: 0,
right: 0,
child: Container(
color: Colors.blue,
),
),
Positioned(
top: firstHeight - secondHeight / 2,
left: 0,
height: secondHeight,
child: Container(
width: 200,
color: Colors.red,
),
),
],
),
),
Container(
height: 200,
margin: const EdgeInsets.only(
bottom: 8,
),
color: Colors.green,
),
Container(
height: 200,
margin: const EdgeInsets.only(
bottom: 8,
),
color: Colors.green,
),
Container(
height: 200,
margin: const EdgeInsets.only(
bottom: 8,
),
color: Colors.green,
),
Container(
height: 200,
margin: const EdgeInsets.only(
bottom: 8,
),
color: Colors.green,
),
],
),
);
},
)
result :
I think what you can use is wrap your image in an expanded widget and use its flex property. Flex basically ensures how much space a widget takes.So by default flex is set to 1. Hence wrap both your widgets with an expanded widget and set the flex property accordingly. I hope it solves your problem.

Can i add radius button in singlechild scroll view?

I am using Stack widget in which I have 2 widgets one is just an image and the other is Singlechildscrollview.
I need to add a button on the footer of the screen and fix this (not moveable). Need to be fixed on screen when the Singlechildscrollview scroll or not I need to fix this button. I am not sure how can I do this because if I out the button in Singlechildscrollview then it will show only when I scroll. I need to fix when I scroll or not button should appear.
Here is my code:
Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: statusBarHeight * 0.8),
height: height * 0.4,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/place2.jpg',
),
fit: BoxFit.fill,
),
),
),
SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(top: height * 0.3),
child: SingleChildScrollView(
child: ClipRRect(
borderRadius: BorderRadius.only(
topRight: Radius.circular(30),
topLeft: Radius.circular(30)),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: height * 0.05,
),
Container(
width: width,
margin: EdgeInsets.only(left: width * 0.03),
child: Text(
'NYC Food Festival',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 30),
),
),
SizedBox(
height: height * 0.02,
),
Container(
margin: EdgeInsets.only(left: width * 0.03),
child: Row(
children: <Widget>[
Icon(
Icons.calendar_today,
size: 20,
color: Color(0xff808080),
),
SizedBox(width: width * 0.02), // give it width
Column(
children: <Widget>[
Text(
'Sat, May 25, 2020',
style: TextStyle(
color: Color(0xff000000),
fontWeight: FontWeight.bold,
fontSize: 15),
),
],
)
],
),
),
SizedBox(
height: height * 0.02,
),
Container(
margin: EdgeInsets.only(left: width * 0.03),
child: Row(
children: <Widget>[
Icon(
Icons.attach_money,
size: 20,
color: Color(0xff808080),
),
SizedBox(width: width * 0.02), // give it width
Column(
children: <Widget>[
Text(
'25,000 PKR',
style: TextStyle(
color: Color(0xff000000),
fontWeight: FontWeight.bold,
fontSize: 15),
),
],
)
],
),
),
SizedBox(
height: height * 0.02,
),
SizedBox(
height: height * 0.02,
),
Container(
width: width,
margin: EdgeInsets.only(left: width * 0.03),
child: Text(
'Snaps',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 25),
),
),
SizedBox(
height: height * 0.02,
),
Container(
child: Column(
children: <Widget>[
CarouselSlider(
options: CarouselOptions(
autoPlay: true,
aspectRatio: 2.0,
enlargeCenterPage: true,
),
items: imageSliders,
),
],
)),
SizedBox(
height: height * 0.02,
),
Container(
width: width,
margin: EdgeInsets.only(left: width * 0.03),
child: Text(
'About',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 25),
),
),
SizedBox(
height: height * 0.02,
),
Container(
padding: EdgeInsets.only(
right: width * 0.03, left: width * 0.03),
child: DescriptionTextWidget(
text:
"Flutter is Google’s mobile UI framework for crafting high-quality native interfaces on iOS and Android in record time. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.")
),
SizedBox(
height: height * 0.02,
),
Container(
width: width,
margin: EdgeInsets.only(left: width * 0.03),
child: Text(
'Included',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 25),
),
),
SizedBox(
height: height * 0.02,
),
Included(),
SizedBox(
height: height * 0.01,
),
Included(),
SizedBox(
height: height * 0.01,
),
Included(),
SizedBox(
height: height * 0.01,
),
],
),
),
),
),
),
)
],
)
Here is the output of current view:
This is what I want:
You can achieve this look with relative ease.
Here is an example:
class BottomFadeButton extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
title: Text("Bottom Fade Button"),
),
body: Container(
// height: 500,
color: Colors.amberAccent,
child: Stack(
children: <Widget>[
Container(
child: ListView.builder(
itemCount: 100,
itemBuilder: (context, index) {
return ListTile(
title: Text("Hello "),
);
}),
),
// Bottom Button
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
height: 100,
decoration: BoxDecoration(
// color: Color.fromARGB(110, 255, 255, 255),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
gradient: LinearGradient(
colors: [
Color.fromARGB(30, 255, 255, 255),
Color.fromARGB(255, 255, 255, 255),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: Center(
child: InkWell(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 100,
vertical: 20,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.blueAccent,
),
child: Text(
"BUY TICKETS",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.white),
),
),
onTap: () {
return print("Tap");
},
),
),
),
),
],
),
),
),
);
}
}
Output:
yes you can add the button in stack and then wrap with align widget with alignment.bottom_center

Flutter banner overlapping the screen

My banner is overlapping the slack widgets i need to show the ad on bottom or footer but problem is its overlapping the container need to know how can i add in end but not overlap the containers
Here is my code
body: Stack(
children: [
GestureDetector(
onTap: () {
percengtageTrigger();
API.voteplusQuestion(snapshot.data[index], 0);
},
child: Container(
height: stackHeight * 0.5,
width: stackWidth,
color: Color(0xffF9D342),
child: Column(
children: <Widget>[
shouldShow
? Container(
padding: const EdgeInsets.only(
top: 10, right: 10),
height: stackHeight * 0.1,
color: Color(0xffF9D342),
width: double.infinity,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment:
CrossAxisAlignment.end,
children: <Widget>[
Text(
'${percentage1.toStringAsFixed(0)}%',
style: TextStyle(
color: Colors.white,
fontSize: 23,
fontFamily: 'NewsCycle',
),
),
],
))
: Container(
height: stackHeight * 0.1,
color: Color(0xffF9D342),
width: double.infinity,
),
Container(
color: Color(0xffF9D342),
height: stackHeight * 0.4,
width: double.infinity,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 20),
child: Text(
snapshot.data[index].would,
style: TextStyle(
color: Color(0xff292826),
fontSize: 23,
fontWeight: FontWeight.bold,
fontFamily: 'NewsCycle',
),
),
),
],
)),
],
),
),
),
GestureDetector(
onTap: () {
percengtageTrigger();
API.voteplusQuestion(snapshot.data[index], 1);
},
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
height: stackHeight * 0.5,
width: stackWidth,
color: Color(0xff292826),
child: Column(
children: <Widget>[
shouldShow
? Container(
padding: const EdgeInsets.only(
top: 10, right: 10),
height: stackHeight * 0.1,
color: Color(0xff292826),
width: double.infinity,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment:
CrossAxisAlignment.end,
children: <Widget>[
Text(
'${percentage2.toStringAsFixed(0)}%',
style: TextStyle(
color: Colors.white,
fontSize: 23,
fontFamily: 'NewsCycle',
),
),
],
))
: Container(
height: stackHeight * 0.1,
color: Color(0xff292826),
width: double.infinity,
),
Container(
color: Color(0xff292826),
height: stackHeight * 0.4,
width: double.infinity,
child: Column(
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(top: 40),
child: Text(
snapshot.data[index].rather,
style: TextStyle(
color: Color(0xffF9D342),
fontSize: 23,
fontWeight: FontWeight.bold,
fontFamily: 'NewsCycle',
),
),
),
],
)),
],
),
),
),
),
Align(
alignment: Alignment.center,
child: Container(
width: stackWidth,
height: stackHeight * 0.015,
color: Colors.white,
),
),
Align(
alignment: Alignment.center,
child: Container(
width: stackWidth,
height: stackHeight * 0.15,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: Align(
alignment: Alignment.center,
child: GestureDetector(
onTap: () {
nextQuestion();
},
child: Text(
"SKIP",
style: TextStyle(
color: Colors.black,
fontFamily: 'FredokaOne',
fontSize: 27),
),
),
)),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
child: AdmobBanner(
adUnitId: getBannerAdUnitId(),
adSize: bannerSize,
),
),
),
],
));
As you see in the image it's overlapping the grey container I need a yellow and grey containers in same size but on top of banner no with overlap with banner.
If your content will be scrollable in the future, then I suggest you stick with the floating ad and maybe add a wide grey background to cover some space as I've seen some apps do.
Otherwise, assign it to a small row at the bottom (And assign the rest of the elements to rows as needed). The ad will take up a lot of space though so be sure to adjust the other elements accordingly.
Since you are using stack the children in the stack will overlap. If don't want them to overlap you can use other layout widgets such as Column or ListView according to your need. You can refer to flutter docs for more info on layout widgets.

How to fit Container in Row

I'm going to ask a question about flutter.
Looking at the capture, I want the height of the left and right containers to match the height of the longer one.
Since we have to fit a longer height, we want to implement it in a way that does not declare a height.
I hope someone can help me solve this.
Thank you.
this is a capture
this is a my code
import 'package:flutter/material.dart';
class RowTest extends StatefulWidget {
#override
_RowTestState createState() => _RowTestState();
}
class _RowTestState extends State<RowTest> {
#override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('simple Page'),
),
body: ListView(
shrinkWrap: true,
children: <Widget>[
Container(
color: Colors.blue,
child: Column(
children: <Widget>[
Container(
child: Column(
children: <Widget>[
for (int i = 0; i < 5; i++)
Row(
children: <Widget>[
Container(
width: 141,
margin: EdgeInsets.fromLTRB(size.width * 0.1,
8, size.width * 0.05, 8),
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
decoration: BoxDecoration(
border: Border.all(
color: Color(0xff939393),
),
color: Colors.red,
borderRadius:
BorderRadius.all(Radius.circular(5)),
),
child: Center(
child: Text(
'testededed',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 16,
height: 1.5,
color: Colors.white),
),
),
),
Container(
width: 141,
margin: EdgeInsets.fromLTRB(size.width * 0.05,
8, size.width * 0.1, 8),
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
decoration: BoxDecoration(
border: Border.all(
color: Color(0xff939393),
),
color: Colors.red,
borderRadius:
BorderRadius.all(Radius.circular(5)),
),
child: Center(
child: Text(
'testesttaaaaaaaaaaaaest',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 16,
height: 1.5,
color: Colors.white),
),
),
),
],
)
],
)),
],
),
)
],
)));
}
}
If you use:
Row (with mainAxisSize max) > Expanded > Container, the container will fit the entire row
If you use:
Column > Expanded > Container, the container will fit the entire column
If you use:
Column > Row (with mainAxisSize max) > Expanded > Container, Container, Container, the 3 containers will fit the entire row with the same width
If you use:
Scaffold > Stack (with fit> StackFit.expand) > Expanded > Container, the stack will try to fit the entire scaffold and the container will fit the stack
Use crossAxisAlignment: CrossAxisAlignment.start to your Root Column of Tree
Column(
crossAxisAlignment: CrossAxisAlignment.start,
I'm sorry for the delay in the response because I had several things overlapped.
I solved it using IntrinsicHeight.
Thanks to everyone who helped with the comments.
class RowTest extends StatefulWidget {
#override
_RowTestState createState() => _RowTestState();
}
class _RowTestState extends State<RowTest> {
#override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('simple Page'),
),
body: ListView(
shrinkWrap: true,
children: <Widget>[
Container(
color: Colors.blue,
child: Column(
children: <Widget>[
Container(
child: Column(
children: <Widget>[
for (int i = 0; i < 5; i++)
IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
width: 141,
margin: EdgeInsets.fromLTRB(
size.width * 0.1,
8,
size.width * 0.05,
8),
padding:
EdgeInsets.fromLTRB(10, 10, 10, 10),
decoration: BoxDecoration(
border: Border.all(
color: Color(0xff939393),
),
color: Colors.red,
borderRadius:
BorderRadius.all(Radius.circular(5)),
),
child: Center(
child: Text(
'testededed',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 16,
height: 1.5,
color: Colors.white),
),
),
),
Container(
width: 141,
margin: EdgeInsets.fromLTRB(
size.width * 0.05,
8,
size.width * 0.1,
8),
padding:
EdgeInsets.fromLTRB(10, 10, 10, 10),
decoration: BoxDecoration(
border: Border.all(
color: Color(0xff939393),
),
color: Colors.red,
borderRadius:
BorderRadius.all(Radius.circular(5)),
),
child: Center(
child: Text(
'testesttaaaaaaaaaaaaest',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 16,
height: 1.5,
color: Colors.white),
),
),
),
],
),
)
],
)),
],
),
)
],
)));
}
}