I am trying to attach a photo to the top of the screen, and extend it to the left and ride edges, but only go down 0.2.
This is the code I am using to do so
final logo = Scaffold(
resizeToAvoidBottomInset: false,
resizeToAvoidBottomPadding: false,
backgroundColor: Colors.white,
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.asset(
"assets/SignUp_Photo.jpg",
height: MediaQuery.of(context).size.height * 0.2,
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover,
),
],
),
);
However, using this code causes me to overflow the bottom by infinity pixels.
How can I rectify?
Calling logo as follows:
return Scaffold(
backgroundColor: Color(0xffffffff),
body: Form(
key: _formKey,
child: SingleChildScrollView(
padding: EdgeInsets.all(36),
child: Container(
height: mq.size.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
logo,
text,
fields,
Padding(
padding: EdgeInsets.only(bottom: 150),
child: bottom,
),
],
),
),
),
),
);
}
}
mq size height is
final mq = MediaQuery.of(context);
You need to put Column directly under Singlechildscrollview and wrap your logo inside the container:
return Scaffold(
backgroundColor: Color(0xffffffff),
body: Form(
key: _formKey,
child: SingleChildScrollView(
padding: EdgeInsets.all(36),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
height: mq.size.height,
child: logo),
text,
fields,
Padding(
padding: EdgeInsets.only(bottom: 150),
child: bottom,
),
],
),
),
),
);
}
}
Wrap the image within a Container. And assign height and with to the Container
final logo =
Container(
height: MediaQuery.of(context).size.height * 0.2,
width: MediaQuery.of(context).size.width,
child: Image.asset(
"assets/SignUp_Photo.jpg",
fit: BoxFit.cover,
),
);
Calling logo as follows:
return Scaffold(
backgroundColor: Color(0xffffffff),
body: Form(
key: _formKey,
child: Container(
height: mq.size.height,
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
logo,
text,
fields,
Padding(
padding: EdgeInsets.only(bottom: 150),
child: bottom,
),
],
),
),
),
),
);
Related
I have several images that I need to display on the screen, the first image is center screen and then 3 at the bottom, the layout of the 3 at the bottom is a single image, and 2 below that.
Using Stack and Align Widgets I have gotten the main image center, but the other images are aligning to the top of the screen and not the bottom even though I am specifying it in the Align Widget.
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
alignment: Alignment.center,
children: <Widget>[
const Align(
alignment: Alignment.center,
child: Image(
image: AssetImage("assets/imgs/logo.png"),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 40),
child: Column(
children: [
SizedBox(
width: MediaQuery.of(context).size.width / 2.5,
child: Image(
image: const AssetImage("assets/imgs/logo1.png"),
width: MediaQuery.of(context).size.width / 2.5,
),
),
Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: const Image(
image: AssetImage("assets/imgs/square_logo.jpg"),
),
),
const Padding(
padding: EdgeInsets.all(10),
),
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: const Image(
image: AssetImage("assets/imgs/square_logo1.png"),
),
),
],
),
],
),
),
),
],
),
);
}
Checkout this one:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Image(
image: AssetImage("assets/imgs/logo.png"),
),
),
Positioned(
bottom: 0,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: Image(
image: AssetImage("assets/imgs/square_logo.jpg"),
),
),
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: Image(
image: AssetImage("assets/imgs/square_logo1.png"),
),
),
],
),
SizedBox(
width: MediaQuery.of(context).size.width / 2.5,
child: Image(
image: AssetImage("assets/imgs/logo1.png"),
),
),
],
),
),
],
),
);
}
Default Column's mainAxisSize: MainAxisSize.max,,, you can use
mainAxisSize: MainAxisSize.min,
White space coming in horizontal view, while giving max width to Container with BoxConstraints.
Versions
Flutter: 3.3.0
Dart: 2.18.0
My code
return Scaffold(
body: Container(
decoration: ...,
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
flex: 1,
child: Container(
padding: const EdgeInsets.all(10.0),
child: Image.asset(
'assets/logo/logo.png',
width: 300,
),
),
),
Flexible(
flex: 2,
child: Card(
shape: ...,
elevation: 8.0,
child: Container(
constraints: const BoxConstraints(
maxWidth: 500,
),
height: 400,
child: ListView(
padding: const EdgeInsets.all(40),
children: [
Form(
key: _formKey,
child: Column(
children: [
...
],
),
),
],
),
),
),
),
],
),
),
);
Screen short:
Horizontal view, white space coming on right side
Vertical view
Just set the outer Container width to the screen width wit MediaQuery.of(context).size.width or even easier to double.infinity. It's going to be like the following:
return Scaffold(
body: Container(
decoration: ...,
width: double.infinity,
padding: const EdgeInsets.all(16.0),
How can I align my widget to take the same width as ClipRect image?
Right now it overflows in my screen. Find attached how it is and how I desire my output would be.
Is it possible to center it within the red lines I drew?
Widget build(BuildContext context) {
final mainChildKey = GlobalKey();
return Flexible(
child: Column(
children: <Widget>[
ColumnWithMainChild(
mainChildKey: mainChildKey,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.network(
imgparam,
width: 350,
height: 200,
fit: BoxFit.cover,
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 8, 0, 8),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Text(
'Good with children: $param_good_children',
),
GFProgressBar(
width: 150,
percentage: 0.3,
backgroundColor: Colors.pink,
progressBarColor: Colors.red,
)
],
),
Divider(),
Text(
'Good with children: $param_good_children',
),
],
),
),
),
],
),
]));
}
}
Do the following Changes
Set Padding to Parent column
Set width of NetworkImage to double.infinity
Wrap your Progress Bar with Flexible
Code:
Widget build(BuildContext context) {
final mainChildKey = GlobalKey();
return Scaffold(
appBar: AppBar(),
body: Padding( // Set Padding to Paren
padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.network(
"https://images.unsplash.com/photo-1474922651267-219b23864ae8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80",
width: double.infinity, // Set width of NetworkImage to double.infinity
height: 200,
fit: BoxFit.cover,
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(0, 8, 0, 8),
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
const Text(
'Good with children: 5',
),
Flexible( //Wrap your Progress Bar with Flexible
child: GFProgressBar(
width: 150,
percentage: 0.3,
backgroundColor: Colors.pink,
progressBarColor: Colors.red,
),
)
],
),
const Divider(),
const Text(
'Good with children: 5',
),
],
),
),
),
]),
),
);
}
Output:
I would like to do a scroll that the map part fixed on top, once i scroll up those widget can be overlay on top of the map.
i tried to do the scroll effect.
i use a stack with one container(the map) and one SingleChildScroll.
but the map is not able to tap after i put the SingleChildScroll on top of the map.
So is there any ways to made this out?
Any suggestions that i can do this design?
Thanks a lot!
This is the normal view
after i scroll up little bit
here is the code
return Scaffold(
key: _scaffoldKey,
backgroundColor: ThemeColors.orangeYellow,
floatingActionButton: Padding(
padding: EdgeInsets.only(right: 30),
child: Row(
children: [
_profileButton,
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.startTop,
body: Stack(
children: [
Positioned(
top: 0,
child: Stack(
alignment: Alignment.bottomCenter,
overflow: Overflow.visible,
children: <Widget>[
Container(),
_map,
_nearbyRestaurantBox,
_getCurrentLocationButton,
],
),
),
SingleChildScrollView(
physics: ClampingScrollPhysics(),
child: Column(
children: <Widget>[
Column(
// alignment: Alignment.bottomCenter,
// overflow: Overflow.visible,
children: <Widget>[
// Container(),
// _map,
Padding(
padding: EdgeInsets.only(top: _mapHeight - 70),
),
Stack(
children: [
Column(
children: [
SizedBox(
height: 70,
// child: Container(
// // color: Colors.green,
// ),
),
SizedBox(
height: 70,
child: Container(
color: Colors.amber,
),
)
],
),
// Padding(
// padding: EdgeInsets.only(top: 35),
// ),
Container(
alignment: Alignment.center,
child: Padding(
padding: EdgeInsets.only(top: 5),
child: _searchBox,
),
)
],
),
// Positioned(top: 0, child: _map),
// _searchBox,
// _nearbyRestaurantBox,
// _getCurrentLocationButton,
],
),
Container(
color: ThemeColors.orangeYellow,
child: Center(
child: Column(
children: <Widget>[
_categoryBox,
..._buildBanners(),
],
),
),
),
],
),
)
],
),
);
I need to create an app that looks like this Flutter design.
I'm struggling to place the text where I want. This is my code so far
body: Padding(
padding: const EdgeInsets.all(0.1),
child: new Container(
child: new Center(
child: new ListView(
children: <Widget>[
new Card(//card 1
child: new Container(
color: Colors.grey,
padding: new EdgeInsets.only(
left: 160.0, top: 0.01, right: 160.0, bottom: 0.01),
child: new Column(
children: <Widget>[
new Text('My Profile')
],
),
),
),
],
),
)
),
)
Your large padding of 160 made it seem like the text was centered on my device.
You can always align the text to the left inside Columns by setting crossAxisAlignment to CrossAxisAlignment.start.
This code should produce some output that is similar to your drawing (I also removed some unnecessary Centers, Containers and Paddings):
Scaffold(
appBar: AppBar(),
body: ListView(
padding: const EdgeInsets.all(0.1),
children: <Widget>[
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: const EdgeInsets.symmetric(horizontal: 16),
width: double.infinity,
color: Colors.grey,
child: Text('My Profile'),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Text('My text\nMy text\nMy text\nMy text'),
),
],
),
),
],
),
);